1const CACHE_VERSION = 'v1'; 2const CACHE_NAME = '::static-cache'; 3const OFFLINE_URL = 'offline.html'; 4 5const urlsToCache = [ 6 'offline.html' 7]; 8 9self.addEventListener('install', function(event) { 10 self.skipWaiting(); 11 event.waitUntil( 12 caches.open(CACHE_VERSION + CACHE_NAME) 13 .then(function(cache) { 14 return cache.addAll(urlsToCache); 15 }) 16 ); 17}); 18 19self.addEventListener('activate', event => { 20 event.waitUntil( 21 (async function() { 22 if (self.registration && self.registration.navigationPreload) { 23 await self.registration.navigationPreload.enable(); 24 } 25 })().then( 26 caches.keys().then(function(cacheNames) { 27 cacheNames.forEach(function(cacheName) { 28 if (cacheName !== CACHE_VERSION + CACHE_NAME) { 29 caches.delete(cacheName); 30 } 31 }) 32 }) 33 ) 34 ) 35}) 36 37self.addEventListener('fetch', event => { 38 const { request } = event; 39 if (request.headers.has('range')) return; 40 if (request.method == 'POST') return; 41 if (request.url.includes('s3=')) return; 42 if (request.url.includes('google')) return; 43 if (request.url.includes('facebook')) return; 44 if (request.url.includes('disqus')) return; 45 event.respondWith( 46 (async function() { 47 let cachedResponse = await caches.match(request); 48 if (cachedResponse) return cachedResponse; 49 try { 50 const response = await event.preloadResponse; 51 if (response) return response; 52 return await fetch(request); 53 } catch (err) { 54 if (request.mode === 'navigate') { 55 const cache = await caches.open(CACHE_VERSION + CACHE_NAME); 56 cachedResponse = await cache.match(OFFLINE_URL); 57 return cachedResponse; 58 } 59 throw err; 60 } 61 })() 62 ); 63});
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.