From e513298f6a0a59386d3f73b52ef8cb62777601f9 Mon Sep 17 00:00:00 2001 From: Daniel Onyejesi Date: Sun, 29 Mar 2026 20:02:34 -0400 Subject: [PATCH] Fix: bump SW cache to v12, switch JS/CSS to network-first Old pedscribe-v11 cache was serving stale admin.js to browsers even after server updates. New cache name forces old SW to deactivate and all clients to get fresh JS on next load. Also switch JS/CSS from stale-while-revalidate to network-first so code fixes are picked up immediately. --- public/sw.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/public/sw.js b/public/sw.js index a487324..b047ac1 100644 --- a/public/sw.js +++ b/public/sw.js @@ -4,7 +4,7 @@ // API calls always fresh (critical for medical data accuracy) // ============================================================ -var CACHE_NAME = 'pedscribe-v11'; +var CACHE_NAME = 'pedscribe-v12'; var SHELL_ASSETS = [ '/', '/index.html', @@ -66,16 +66,15 @@ self.addEventListener('fetch', function(event) { return; } - // Static assets (JS, CSS, icons) — stale-while-revalidate + // Static assets (JS, CSS, icons) — network-first so code updates apply immediately if (url.pathname.match(/\.(js|css|png|ico|woff2?)$/)) { event.respondWith( - caches.match(event.request).then(function(cached) { - var fetchPromise = fetch(event.request).then(function(response) { - var clone = response.clone(); - caches.open(CACHE_NAME).then(function(cache) { cache.put(event.request, clone); }); - return response; - }).catch(function() { return cached; }); - return cached || fetchPromise; + fetch(event.request).then(function(response) { + var clone = response.clone(); + caches.open(CACHE_NAME).then(function(cache) { cache.put(event.request, clone); }); + return response; + }).catch(function() { + return caches.match(event.request); }) ); return;