only register service worker when launched as PWA
Hunter
Thursday, April 30th, 2026 at 12:54 AM
8 /^172\.(1[6-9]|2\d|3[01])\./.test(hostname) ||
9 /^169\.254\./.test(hostname);
10
-// Register service worker for PWA functionality (skip locally to avoid caching during development)
-if ('serviceWorker' in navigator && !isLocal) {
11 +// In browser tab, don't hit cache.
12 +// When installed as a PWA, always hit cache.
13 +const isInstalled =
14 + window.matchMedia('(display-mode: standalone)').matches ||
15 + window.matchMedia('(display-mode: fullscreen)').matches ||
16 + window.matchMedia('(display-mode: minimal-ui)').matches ||
17 + window.navigator.standalone === true;
18 +
19 +if ('serviceWorker' in navigator && isInstalled && !isLocal) {
20 window.addEventListener('load', () => {
21 navigator.serviceWorker.register('service-worker.js')
22 .then(registration => {
26 console.log('Service Worker registration failed:', error);
27 });
28 });
-} else if ('serviceWorker' in navigator && isLocal) {
- // Locally, unregister any existing service worker and clear caches
29 +} else if ('serviceWorker' in navigator) {
30 + // Browser tab or local dev: tear down any existing SW and caches so
31 + // the page always reflects the latest deploy.
32 navigator.serviceWorker.getRegistrations().then(registrations => {
33 registrations.forEach(r => r.unregister());
34 });