From c3454847a0b343a6341a4e7c4ee2ad9294b727e7 Mon Sep 17 00:00:00 2001 From: Jason Zimdars Date: Tue, 2 Sep 2025 17:24:21 -0500 Subject: [PATCH] Add a simple method to refresh content when launching or switching tabs Prevents stale content on load as reported in: https://fizzy.37signals.com/5986089/collections/2/cards/1449 --- app/views/pwa/service_worker.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/views/pwa/service_worker.js b/app/views/pwa/service_worker.js index e27c062f9..df284d578 100644 --- a/app/views/pwa/service_worker.js +++ b/app/views/pwa/service_worker.js @@ -1,3 +1,14 @@ +self.addEventListener('fetch', (event) => { + if (event.request.method !== 'GET') return + + if (event.request.destination === 'document') { + event.respondWith( + fetch(event.request, { cache: 'no-cache' }) + .catch(() => caches.match(event.request)) + ) + } +}) + self.addEventListener("push", async (event) => { const data = await event.data.json() event.waitUntil(Promise.all([ showNotification(data), updateBadgeCount(data.options) ]))