From 089fcf94f8969b432ba113b18a924cd85836ab05 Mon Sep 17 00:00:00 2001 From: Rosa Gutierrez Date: Fri, 6 Feb 2026 12:37:39 +0100 Subject: [PATCH] Preload resources after service worker installation When the service worker is registered for the first time, resources loaded before it becomes active won't go through the service worker. These resources may be served from the browser's HTTP cache on subsequent requests, bypassing the service worker cache entirely. The new `preload` option accepts a regex pattern. On first visit (when no controller exists), it waits for the service worker to take control, then sends a message with URLs from `performance.getEntriesByType("resource")` that match the pattern. The service worker fetches and caches these resources. --- Gemfile.lock | 2 +- Gemfile.saas.lock | 2 +- app/javascript/initializers/offline.js | 7 ++++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 9dd682dce..758936188 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -13,7 +13,7 @@ GIT GIT remote: https://github.com/hotwired/turbo-rails.git - revision: 0becdbbcdbf607eab6632463bc63f94d64249b7b + revision: ca62e8bdad88d01914d512ad24424e0670f239c9 branch: offline-cache specs: turbo-rails (2.0.23) diff --git a/Gemfile.saas.lock b/Gemfile.saas.lock index 8f5c9dd95..a3552dacd 100644 --- a/Gemfile.saas.lock +++ b/Gemfile.saas.lock @@ -62,7 +62,7 @@ GIT GIT remote: https://github.com/hotwired/turbo-rails.git - revision: 0becdbbcdbf607eab6632463bc63f94d64249b7b + revision: ca62e8bdad88d01914d512ad24424e0670f239c9 branch: offline-cache specs: turbo-rails (2.0.23) diff --git a/app/javascript/initializers/offline.js b/app/javascript/initializers/offline.js index c5eff824e..446a9671e 100644 --- a/app/javascript/initializers/offline.js +++ b/app/javascript/initializers/offline.js @@ -1,6 +1,7 @@ import { Turbo } from "@hotwired/turbo-rails" -Turbo.offline.start("/service-worker.js", { - scope: "/", - native: true +Turbo.offline.start("/service-worker.js", { + scope: "/", + native: true, + preload: /\/assets\// })