1/** 2Import the Workbox library from the Google CDN. 3It is possible to serve this locally should we want to remove the dependency on Google 4See here for more info: https://developers.google.com/web/tools/workbox/modules/workbox-sw 5**/ 6importScripts('https://storage.googleapis.com/workbox-cdn/releases/3.3.1/workbox-sw.js'); 7const offlinePage = '/offline/'; 8// SETTINGS 9workbox.setConfig({ 10 // set the local path is not using Google CDN 11 //modulePathPrefix: '/directory/to/workbox/' 12 13 // By default, workbox-sw will use the debug build for sites on localhost, 14 // but for any other origin itâll use the production build. Force by setting to true. 15 // debug: true 16}); 17 18/** 19 * Pages to cache (networkFirst) 20 */ 21 22/** 23 * Add on install 24 */ 25self.addEventListener('install', (event) => { 26 const urls = ['/offline/']; 27 const cacheName = workbox.core.cacheNames.runtime; 28 event.waitUntil(caches.open(cacheName).then((cache) => cache.addAll(urls))) 29}); 30 31var networkFirst = workbox.strategies.networkFirst({ 32 cacheName: 'cache-pages' 33}); 34 35const customHandler = async (args) => { 36 try { 37 const response = await networkFirst.handle(args); 38 return response || await caches.match(offlinePage); 39 } catch (error) { 40 return await caches.match(offlinePage); 41 } 42}; 43 44workbox.routing.registerRoute( 45 new RegExp('/'), 46 customHandler 47); 48 49// If any precache rules are defined in the Workbox setup this is where they will be injected 50workbox.precaching.precacheAndRoute([]); 51 52// skip the 'worker in waiting' phase and activate immediately 53workbox.skipWaiting(); 54// claim any clients that match the worker scope immediately. requests on these pages will 55// now go via the service worker. 56workbox.clientsClaim();
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.