1/* 2 * OperativMM service worker â deliberately small. 3 * 4 * It exists so the site qualifies as installable (manifest + SW) and so 5 * repeat visits skip re-downloading hashed build assets and static files. 6 * It never caches HTML: news must be fresh, and an offline page would only 7 * be a stale one. HTML and API calls go network-first with no fallback, so 8 * the worker can never serve yesterday's front page. 9 */ 10 11const VERSION = 'omm-sw-v1'; 12const STATIC_CACHE = `${VERSION}-static`; 13 14// Only these path prefixes are ever cached. Hashed Vite output under /build/ 15// is immutable; /frontend/ holds fonts, logos and vendored scripts. 16const STATIC_PREFIXES = ['/build/', '/frontend/']; 17 18self.addEventListener('install', () => { 19 self.skipWaiting(); 20}); 21 22self.addEventListener('activate', (event) => { 23 event.waitUntil( 24 caches.keys().then((keys) => 25 Promise.all(keys.filter((k) => k.startsWith('omm-sw-') && k !== STATIC_CACHE).map((k) => caches.delete(k))) 26 ).then(() => self.clients.claim()) 27 ); 28}); 29 30self.addEventListener('fetch', (event) => { 31 const { request } = event; 32 33 if (request.method !== 'GET') return; 34 35 const url = new URL(request.url); 36 if (url.origin !== self.location.origin) return; 37 38 const isStatic = STATIC_PREFIXES.some((p) => url.pathname.startsWith(p)); 39 40 if (isStatic) { 41 // Cache-first: hashed or rarely-changing files. 42 event.respondWith( 43 caches.open(STATIC_CACHE).then(async (cache) => { 44 const hit = await cache.match(request); 45 if (hit) return hit; 46 const res = await fetch(request); 47 if (res && res.ok) cache.put(request, res.clone()); 48 return res; 49 }) 50 ); 51 return; 52 } 53 54 // Everything else (HTML, /api, /storage images): straight to the network. 55 // No respondWith â the browser handles it exactly as if there were no worker. 56});
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.