1const CACHE_NAME = 'harkness-io-v16'; 2const PRECACHE_URLS = [ 3 '/', 4 '/index.html', 5]; 6 7// Install: precache shell â force immediate activation 8self.addEventListener('install', (event) => { 9 event.waitUntil( 10 caches.open(CACHE_NAME).then((cache) => cache.addAll(PRECACHE_URLS)) 11 ); 12 self.skipWaiting(); 13}); 14 15// Activate: clean old caches 16self.addEventListener('activate', (event) => { 17 event.waitUntil( 18 caches.keys().then((keys) => 19 Promise.all(keys.filter((k) => k !== CACHE_NAME).map((k) => caches.delete(k))) 20 ) 21 ); 22 self.clients.claim(); 23}); 24 25// Fetch: network-first for everything, fall back to cache when offline 26self.addEventListener('fetch', (event) => { 27 const url = new URL(event.request.url); 28 29 // Skip non-GET and cross-origin requests 30 if (event.request.method !== 'GET') return; 31 if (url.origin !== self.location.origin) return; 32 33 // Hashed assets (Vite build outputs) â never serve stale from cache. 34 // If the network request 404s, the asset hash has changed and the cached 35 // version (from a different filename) won't help. Let the browser handle 36 // the error so the app can reload with fresh assets. 37 const isHashedAsset = url.pathname.startsWith('/assets/'); 38 39 event.respondWith( 40 fetch(event.request).then((response) => { 41 if (response.ok) { 42 const clone = response.clone(); 43 caches.open(CACHE_NAME).then((cache) => cache.put(event.request, clone)); 44 } 45 return response; 46 }).catch(() => { 47 // Offline: serve from cache (but not stale hashed assets) 48 if (isHashedAsset) { 49 return new Response('Asset unavailable offline', { status: 503 }); 50 } 51 return caches.match(event.request).then((cached) => { 52 if (cached) return cached; 53 if (event.request.mode === 'navigate') { 54 return caches.match('/index.html'); 55 } 56 return new Response('Offline', { status: 503 }); 57 }); 58 }) 59 ); 60});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.