1importScripts('/node_modules/sw-toolbox/sw-toolbox.js'); 2 3const config = { 4 offlinePage: '/offline/' 5}; 6 7const IGNORED_URLS = []; 8 9config.filesToCache = [ 10 '', 11 config.offlinePage 12]; 13 14function requestAccepts(request, contentType) { 15 return request.headers.get('Accept').indexOf(contentType) !== -1; 16} 17 18function fetchHandler(request, values) { 19 if (requestAccepts(request, 'text/html')) { 20 if (shouldNotCache(request)) { 21 return toolbox.networkOnly(request, values); 22 } 23 return toolbox.networkFirst(request, values).catch(function () { 24 return toolbox.cacheOnly(new Request(config.offlinePage), values) 25 .then(function (response) { 26 return response || new Response('You\'re offline. Sorry.', { 27 status: 500, 28 statusText: 'Offline Page Missing' 29 }); 30 }); 31 }); 32 } 33 return toolbox.cacheFirst(request, values); 34} 35 36function shouldNotCache(request) { 37 return IGNORED_URLS.some(url => request.url.indexOf(url) != -1); 38} 39 40toolbox.options.debug = false; 41toolbox.router.default = toolbox.networkFirst; 42toolbox.router.get('/(.*)', fetchHandler, {origin: self.location.origin}); 43toolbox.precache(config.filesToCache); 44toolbox.precache( 45 clients.matchAll({includeUncontrolled: true}).then(l => { 46 return l.map(c => c.url); 47 }) 48); 49 50self.addEventListener('activate', () => self.clients.claim()); 51 52self.addEventListener('install', () => self.skipWaiting());
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.