From 42540752af56c375303de23ef5234d169ed0bd3f Mon Sep 17 00:00:00 2001 From: Julien Calixte Date: Mon, 23 Mar 2026 19:33:27 +0100 Subject: [PATCH] fix(pwa): switch service worker to network-first strategy Cache-first was preventing updates from reaching users. Network-first always fetches fresh content and only falls back to cache when offline. Also bumps cache version to evict stale cache-first entries. --- app/static/sw.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app/static/sw.js b/app/static/sw.js index 38532ab..e06015d 100644 --- a/app/static/sw.js +++ b/app/static/sw.js @@ -1,8 +1,6 @@ -const CACHE = 'apoena-v1'; -const PRECACHE = ['/', '/worker.js', '/manifest.json', '/icon.svg', '/icon-maskable.svg']; +const CACHE = 'apoena-v2'; self.addEventListener('install', e => { - e.waitUntil(caches.open(CACHE).then(c => c.addAll(PRECACHE))); self.skipWaiting(); }); @@ -21,7 +19,14 @@ self.addEventListener('fetch', e => { // Pass through API calls if (url.pathname === '/extract-audio') return; + // Network-first: always fetch fresh content, update cache, fall back offline e.respondWith( - caches.match(e.request).then(cached => cached || fetch(e.request)) + fetch(e.request) + .then(res => { + const clone = res.clone(); + caches.open(CACHE).then(c => c.put(e.request, clone)); + return res; + }) + .catch(() => caches.match(e.request)) ); });