fix: switch SW to network-first strategy so PWA always gets fresh updates

Cache-first meant users were stuck on old versions until manual cache clear.
Network-first fetches live, updates cache, falls back to cache when offline.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
HoneyandClaude Sonnet 4.6 committed 2026-04-25 18:02:05 +02:00
1 parent f298661d72
commit 1b981591d4
1 file changed
+5 -5
+5 -5
View File
@@ -1,4 +1,4 @@
const CACHE = 'ns-v20';
const CACHE = 'ns-v21';
const PRECACHE = ['/', 'index.html', 'styles.css', 'app.js', 'sw.js', 'manifest.json', 'icon.svg'];
const SKIP_URLS = ['/rest/stream', '/rest/download', '/config.js'];
@@ -19,14 +19,14 @@ self.addEventListener('activate', e => {
self.addEventListener('fetch', e => {
if (SKIP_URLS.some(u => e.request.url.includes(u))) return;
e.respondWith(
caches.match(e.request).then(cached =>
cached || fetch(e.request).then(res => {
fetch(e.request)
.then(res => {
if (res.status === 200 && e.request.method === 'GET') {
const clone = res.clone();
caches.open(CACHE).then(c => c.put(e.request, clone));
}
return res;
}).catch(() => cached)
)
})
.catch(() => caches.match(e.request).then(r => r || Response.error()))
);
});