diff --git a/warzone/crates/warzone-server/src/routes/web.rs b/warzone/crates/warzone-server/src/routes/web.rs index a98ac67..3dbf505 100644 --- a/warzone/crates/warzone-server/src/routes/web.rs +++ b/warzone/crates/warzone-server/src/routes/web.rs @@ -50,7 +50,7 @@ async fn pwa_manifest() -> impl IntoResponse { async fn service_worker() -> impl IntoResponse { ([(header::CONTENT_TYPE, "application/javascript")], r##" -const CACHE = 'wz-v5'; +const CACHE = 'wz-v6'; const SHELL = ['/', '/wasm/warzone_wasm.js', '/wasm/warzone_wasm_bg.wasm', '/icon.svg', '/manifest.json']; self.addEventListener('install', e => { @@ -71,18 +71,17 @@ self.addEventListener('fetch', e => { if (url.pathname.startsWith('/v1/')) return; // WS: skip if (url.protocol === 'ws:' || url.protocol === 'wss:') return; - // Shell: cache first, network fallback + // Network first, cache fallback (ensures updates are picked up immediately) e.respondWith( - caches.match(e.request).then(cached => cached || fetch(e.request).then(resp => { + fetch(e.request).then(resp => { if (resp.ok && SHELL.includes(url.pathname)) { const clone = resp.clone(); caches.open(CACHE).then(c => c.put(e.request, clone)); } return resp; - }).catch(() => { - if (e.request.mode === 'navigate') { - return caches.match('/'); - } + }).catch(() => caches.match(e.request).then(cached => { + if (cached) return cached; + if (e.request.mode === 'navigate') return caches.match('/'); })) ); });