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 => {