1//! IF ANYTHING IN THIS FILE IS CHANGED MAKE SURE setVersion.js HAS ALSO BEEN UPDATED 2// Increase the v number when the app is updated 3const version = "1.5.2"; 4const cacheName = `-v${version}`; 5 6const assetsToCache = [ 7 "./", 8 "./index.html", 9 `./index-${version}.css`, 10 `./index-${version}.js`, 11 "./global.css", 12]; 13 14/** 15 * Special log function to clearly distinguish logs from the service worker. 16 * @param {string} text - The text to log 17 */ 18function log(text) { 19 console.log("%cService Worker", "color: purple; font-weight: 600; background: white; padding: 0 5px; border-radius: 2px", text); 20} 21 22self.addEventListener("install", e => { 23 log("Installing"); 24 e.waitUntil((async () => { 25 const cache = await caches.open(cacheName); 26 await cache.addAll(assetsToCache); 27 })()); 28}); 29 30self.addEventListener("fetch", e => { 31 log("Fetching definition"); 32 e.respondWith((async () => { 33 const r = await caches.match(e.request); 34 if (r) { 35 log("Definition found in cache"); 36 return r; 37 }; 38 const response = await fetch(e.request); 39 const cache = await caches.open("defs"); 40 log("Caching definition"); 41 cache.put(e.request, response.clone()); 42 return response; 43 })()); 44}); 45 46// When the name of the cache changes (because the app has been updated) delete the old cache 47self.addEventListener("activate", e => { 48 e.waitUntil(caches.keys().then(keys => { 49 return Promise.all(keys.map((key) => { 50 if (key === cacheName || key === "defs") return; 51 log(`Cache updated to ${cacheName.split("-")[1]}, old cache deleted`); 52 return caches.delete(key); 53 })); 54 })); 55});
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.