1// Core assets 2let coreAssets = []; 3 4// On install, cache core assets 5self.addEventListener('install', function (event) { 6 self.skipWaiting(); 7 // Cache core assets 8 event.waitUntil(caches.open('app').then(function (cache) { 9 for (let asset of coreAssets) { 10 cache.add(new Request(asset)); 11 } 12 return cache; 13 })); 14 15}); 16 17self.addEventListener('activate', function(event) { 18 event.waitUntil(clients.claim()); 19}); 20 21// Listen for request events 22self.addEventListener('fetch', function (event) { 23 24 // Get the request 25 let request = event.request; 26 27 28 // Bug fix 29 // https://stackoverflow.com/a/49719964 30 if (event.request.cache === 'only-if-cached' && event.request.mode !== 'same-origin') return; 31 32 // HTML files 33 // Network-first 34 if ( 35 ( 36 //request.url.startsWith(self.location.origin) || 37 request.url.startsWith('https://adminplayer.sohatv.vn') || 38 request.url.startsWith('https://player.sohatv.vn') || 39 request.url.startsWith('https://ims.mediacdn.vn') 40 ) && 41 !request.url.startsWith(self.location.origin + '/sw.js') && 42 !request.url.startsWith(self.location.origin + '/manifest.json') 43 ) { 44 event.respondWith( 45 fetch(request).then(function (response) { 46 47 // Create a copy of the response and save it to the cache 48 let copy = response.clone(); 49 event.waitUntil(caches.open('app').then(function (cache) { 50 return cache.put(request, copy); 51 })); 52 53 // Return the response 54 return response; 55 56 }).catch(function (error) { 57 58 // If there's no item in cache, respond with a fallback 59 return caches.match(request).then(function (response) { 60 return response || caches.match('/offline.html'); 61 }); 62 63 }) 64 ); 65 } 66 67 // Static 68 // Offline-first 69 if ( 70 request.url.includes('https://static.contineljs.com/fonts/') || 71 request.url.includes('https://cdnstoremedia.com/adt/cpc/tvcads/files/images/') || 72 request.url.includes('https://static.mediacdn.vn') 73 ) { 74 event.respondWith( 75 caches.match(request).then(function (response) { 76 return response || fetch(request).then(function (response) { 77 78 // Save a copy of it in cache 79 let copy = response.clone(); 80 event.waitUntil(caches.open('app').then(function (cache) { 81 return cache.put(request, copy); 82 })); 83 84 // Return the response 85 return response; 86 87 }); 88 }) 89 ); 90 } 91});
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.