1 2self.addEventListener('install', function (event) { 3 event.waitUntil( 4 caches.open('sw-cache').then(function (cache) { 5 console.log("Installed....."); 6 return cache.add("/"); 7 }) 8 ); 9}); 10 11self.addEventListener('activate', function (event) { 12 console.log("activate....."); 13}); 14 15self.addEventListener('fetch', function (event) { 16 var request = event.request; 17 var url; 18 19 try { 20 url = new URL(request.url); 21 } catch (e) { 22 return; 23 } 24 25 // SW cannot fetch extension/data/blob/etc. Let the browser handle them. 26 if (url.protocol !== 'http:' && url.protocol !== 'https:') { 27 return; 28 } 29 30 // Chrome rejects this combination; do not intercept. 31 if (request.cache === 'only-if-cached' && request.mode !== 'same-origin') { 32 return; 33 } 34 35 // Cross-origin (GA, Ads, Translate, HubSpot, fonts, CDNs): native browser fetch. 36 // Avoids wrapping third-party/blocked requests. Same success path as today's passthrough. 37 if (url.origin !== self.location.origin) { 38 return; 39 } 40 41 event.respondWith( 42 fetch(request).catch(function () { 43 return Response.error(); 44 }) 45 ); 46}); 47 48/*---------------------------*/
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.