1// This is the "Offline page" service worker 2 3importScripts('https://storage.googleapis.com/workbox-cdn/releases/5.1.2/workbox-sw.js'); 4 5const CACHE = 'pwabuilder-page'; 6 7const offlineFallbackPage = '/offline.html'; 8 9self.addEventListener('message', (event) => { 10 if (event.data && event.data.type === 'SKIP_WAITING') { 11 self.skipWaiting(); 12 } 13}); 14 15self.addEventListener('install', async(event) => { 16 event.waitUntil( 17 caches.open(CACHE) 18 .then((cache) => cache.add(offlineFallbackPage)) 19 ); 20}); 21 22if (workbox.navigationPreload.isSupported()) { 23 workbox.navigationPreload.enable(); 24} 25 26self.addEventListener('fetch', (event) => { 27 if (event.request.mode === 'navigate') { 28 event.respondWith((async() => { 29 try { 30 const preloadResp = await event.preloadResponse; 31 32 if (preloadResp) { 33 return preloadResp; 34 } 35 36 const networkResp = await fetch(event.request); 37 return networkResp; 38 } catch (error) { 39 40 const cache = await caches.open(CACHE); 41 const cachedResp = await cache.match(offlineFallbackPage); 42 return cachedResp; 43 } 44 })()); 45 } 46});
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.