1const _cacheName = "offline"; 2 3const _cacheItems = [ 4 "/favicon.ico", 5 "/static/offline.html" 6]; 7 8self.addEventListener("install", function (event) { 9 event.waitUntil( 10 caches.open(_cacheName) 11 .then(function (cache) { 12 return cache.addAll(_cacheItems); 13 }) 14 ); 15}); 16 17self.addEventListener("fetch", function (event) { 18 event.respondWith( 19 caches.match(event.request).then(function (response) { 20 return response || fetch(event.request); 21 }).catch(function () { 22 return caches.match("/static/offline.html"); 23 }) 24 ); 25}); 26 27self.addEventListener("activate", function (event) { 28 const cacheAllowlist = [_cacheName]; 29 event.waitUntil( 30 caches.keys().then(function (cacheNames) { 31 return Promise.all( 32 cacheNames.map(function (cacheName) { 33 if (cacheAllowlist.indexOf(cacheName) === -1) { 34 return caches.delete(cacheName); 35 } 36 }) 37 ); 38 }) 39 ); 40});
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.