1/* Loopion service worker â minimal, install-enabling, network-first. 2 * 3 * Goals: 4 * - Satisfy PWA installability (a fetch handler is required). 5 * - Never serve stale app code: always go to the network first for 6 * navigations/assets, falling back to a cached offline shell only when the 7 * device is truly offline. This avoids breaking the live admin/app UI. 8 */ 9const CACHE = "loopion-v1"; 10const OFFLINE_URL = "/offline"; 11 12self.addEventListener("install", (event) => { 13 event.waitUntil( 14 caches.open(CACHE).then((cache) => cache.addAll([OFFLINE_URL])).catch(() => {}), 15 ); 16 self.skipWaiting(); 17}); 18 19self.addEventListener("activate", (event) => { 20 event.waitUntil( 21 caches 22 .keys() 23 .then((keys) => Promise.all(keys.filter((k) => k !== CACHE).map((k) => caches.delete(k)))) 24 .then(() => self.clients.claim()), 25 ); 26}); 27 28self.addEventListener("fetch", (event) => { 29 const req = event.request; 30 31 // Only handle GET; let the browser deal with everything else (POST, etc.). 32 if (req.method !== "GET") return; 33 34 // Network-first for page navigations, fall back to the offline shell. 35 if (req.mode === "navigate") { 36 event.respondWith( 37 fetch(req).catch(() => caches.match(OFFLINE_URL).then((r) => r || Response.error())), 38 ); 39 return; 40 } 41});
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.