1const OFFLINE_VERSION = 1; 2const CACHE_NAME = "offline"; 3const OFFLINE_URL = "/offline.html"; 4 5self.addEventListener("install", (event) => { 6 event.waitUntil( 7 (async () => { 8 const cache = await caches.open(CACHE_NAME); 9 await cache.add(new Request(OFFLINE_URL, { cache: "reload" })); 10 })() 11 ); 12 self.skipWaiting(); 13}); 14 15self.addEventListener("activate", (event) => { 16 event.waitUntil( 17 (async () => { 18 if ("navigationPreload" in self.registration) { 19 await self.registration.navigationPreload.enable(); 20 } 21 })() 22 ); 23 self.clients.claim(); 24}); 25 26self.addEventListener("fetch", (event) => { 27 if (event.request.mode === "navigate") { 28 event.respondWith( 29 (async () => { 30 try { 31 const preloadResponse = await event.preloadResponse; 32 if (preloadResponse) { 33 return preloadResponse; 34 } 35 const networkResponse = await fetch(event.request); 36 return networkResponse; 37 } catch (error) { 38 const cache = await caches.open(CACHE_NAME); 39 const cachedResponse = await cache.match(OFFLINE_URL); 40 return cachedResponse; 41 } 42 })() 43 ); 44 } 45});
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.