diff --git a/src/service-worker.js b/src/service-worker.js index a8006217..fa352b39 100644 --- a/src/service-worker.js +++ b/src/service-worker.js @@ -17,6 +17,14 @@ self.addEventListener('install', (event) => { } event.waitUntil(addFilesToCache()); + + // Skip the waiting phase so the new service worker activates immediately + // instead of waiting for all existing tabs to close first. + // WHY: Without this, a user who leaves idaa.org open all day (common for + // IDAA members) will run the old JS bundle for hours after a fix is deployed. + // The new SW is installed in the background but sits idle until every tab + // using the old version is closed — which may never happen in practice. + self.skipWaiting(); }); self.addEventListener('activate', (event) => { @@ -28,6 +36,10 @@ self.addEventListener('activate', (event) => { } event.waitUntil(deleteOldCaches()); + + // Take control of all open tabs immediately after activation so they use + // the new service worker (and new cached assets) without needing a reload. + self.clients.claim(); }); self.addEventListener('fetch', (event) => {