1const CACHE_NAME = "chongzixuan-portfolio-cache-v3"; 2const ASSET_LIST = [ 3 "./", 4 "./index.html", 5 "./assets/css/output.css", 6 "./assets/css/style.css", 7 "./assets/js/script.js", 8 "./assets/images/favicon.png", 9 "./assets/images/laksh.pradhwani.webp" 10]; 11 12self.addEventListener("install", (event) => { 13 event.waitUntil( 14 caches.open(CACHE_NAME).then((cache) => { 15 return cache.addAll(ASSET_LIST); 16 }) 17 ); 18 self.skipWaiting(); 19}); 20 21self.addEventListener("activate", (event) => { 22 event.waitUntil( 23 caches.keys().then((keys) => 24 Promise.all( 25 keys 26 .filter((key) => key !== CACHE_NAME) 27 .map((key) => caches.delete(key)) 28 ) 29 ) 30 ); 31 self.clients.claim(); 32}); 33 34self.addEventListener("fetch", (event) => { 35 // Use network-first strategy for script.js to ensure updates are loaded immediately 36 if (event.request.url.includes('/script.js')) { 37 event.respondWith( 38 fetch(event.request).then((response) => { 39 if (response && response.status === 200) { 40 caches.open(CACHE_NAME).then((cache) => { 41 cache.put(event.request, response.clone()); 42 }); 43 } 44 return response; 45 }).catch(() => { 46 return caches.match(event.request); 47 }) 48 ); 49 return; 50 } 51 52 // Cache-first strategy for other assets 53 event.respondWith( 54 caches.match(event.request).then((cached) => { 55 const networkFetch = fetch(event.request).then((response) => { 56 if (response && response.status === 200) { 57 caches.open(CACHE_NAME).then((cache) => { 58 cache.put(event.request, response.clone()); 59 }); 60 } 61 return response; 62 }); 63 64 // Return cached version immediately, update it in background 65 return cached || networkFetch; 66 }) 67 ); 68});
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.