From 34e701fa78fd2e2de9a6a92caf8491db50db38f4 Mon Sep 17 00:00:00 2001 From: Scarriffle Date: Wed, 1 Jul 2026 11:24:05 +0200 Subject: [PATCH] feat(pwa): auto-update service worker so new releases take effect without manual cache clearing - app.js: reload once on SW controllerchange (guarded against loops / first install) and poll reg.update() hourly for long-open tabs - sw.js: bump cache to v24 so the new (network-first) worker replaces any stale cache-first worker and cleans old caches on activate Co-Authored-By: Claude Opus 4.8 --- frontend/js/app.js | 17 ++++++++++++++++- frontend/js/version.js | 2 +- frontend/sw.js | 2 +- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/frontend/js/app.js b/frontend/js/app.js index 78773f8..eda0fdc 100644 --- a/frontend/js/app.js +++ b/frontend/js/app.js @@ -192,8 +192,23 @@ boot(); // ── Service Worker registration (PWA) ───────────────────── if ('serviceWorker' in navigator) { + // Auto-update: when a new service worker takes control, reload once so the + // page runs the fresh assets. Guarded so it never loops and never fires on + // the very first install (when there was no previous controller). + let refreshing = false; + const hadController = !!navigator.serviceWorker.controller; + navigator.serviceWorker.addEventListener('controllerchange', () => { + if (refreshing || !hadController) return; + refreshing = true; + window.location.reload(); + }); + window.addEventListener('load', () => { - navigator.serviceWorker.register('/sw.js', { scope: '/' }).catch(err => { + navigator.serviceWorker.register('/sw.js', { scope: '/' }).then(reg => { + // Check for a new SW now and hourly, so long-open tabs pick up releases. + reg.update(); + setInterval(() => reg.update(), 60 * 60 * 1000); + }).catch(err => { console.warn('SW registration failed:', err); }); }); diff --git a/frontend/js/version.js b/frontend/js/version.js index 537749a..7f1dbfc 100644 --- a/frontend/js/version.js +++ b/frontend/js/version.js @@ -1,2 +1,2 @@ // Increment APP_VERSION with every code change -export const APP_VERSION = 'v65'; +export const APP_VERSION = 'v66'; diff --git a/frontend/sw.js b/frontend/sw.js index 79c4d88..21e7185 100644 --- a/frontend/sw.js +++ b/frontend/sw.js @@ -7,7 +7,7 @@ // the entry HTML / version files). New releases take effect on the next // reload, no manual SW unregister required. -const CACHE_VERSION = 'calendarr-v23'; +const CACHE_VERSION = 'calendarr-v24'; const OFFLINE_SHELL = ['/', '/index.html']; self.addEventListener('install', event => {