commit 7b773fa9993887d7b912e3b9b70d1a4992810b10
parent f275d39dfbdc29ab7d06a2f055dd2d86cc129d0b
Author: Hunter
Date:   Thu, 30 Apr 2026 00:54:34 -0400

only register service worker when launched as PWA

Diffstat:
Mresources/script.js | 16++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/resources/script.js b/resources/script.js @@ -8,8 +8,15 @@ const isLocal = /^172\.(1[6-9]|2\d|3[01])\./.test(hostname) || /^169\.254\./.test(hostname); -// Register service worker for PWA functionality (skip locally to avoid caching during development) -if ('serviceWorker' in navigator && !isLocal) { +// In browser tab, don't hit cache. +// When installed as a PWA, always hit cache. +const isInstalled = + window.matchMedia('(display-mode: standalone)').matches || + window.matchMedia('(display-mode: fullscreen)').matches || + window.matchMedia('(display-mode: minimal-ui)').matches || + window.navigator.standalone === true; + +if ('serviceWorker' in navigator && isInstalled && !isLocal) { window.addEventListener('load', () => { navigator.serviceWorker.register('service-worker.js') .then(registration => { @@ -19,8 +26,9 @@ if ('serviceWorker' in navigator && !isLocal) { console.log('Service Worker registration failed:', error); }); }); -} else if ('serviceWorker' in navigator && isLocal) { - // Locally, unregister any existing service worker and clear caches +} else if ('serviceWorker' in navigator) { + // Browser tab or local dev: tear down any existing SW and caches so + // the page always reflects the latest deploy. navigator.serviceWorker.getRegistrations().then(registrations => { registrations.forEach(r => r.unregister()); });