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.
This commit is contained in:
@@ -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))
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user