1 2// Service Worker 3 4const pwacache = "pwa-cache-v11.4" 5self.addEventListener('install', (e) => { 6 console.log('install Activated ====='); 7 8 // create new cache 9 /*let cacheReady = caches.open(pwacache).then((cache) => { 10 return cache.add('/') 11 });*/ 12 13 let cacheReady = caches.open(pwacache).then((cache) => { 14 cache.addAll([ 15 '/static/ctn/commons/js/colombia_v11.js' 16 ]) 17 }) 18 19 e.waitUntil(cacheReady); 20 21}); 22 23self.addEventListener('activate', (e) => { 24 /*let cacheReady = caches.open(pwacache).then((cache) => { 25 cache.match('/').then((res) => { 26 return res.text().then(console.log) 27 }) }); 28 29 e.waitUntil(cacheReady); 30*/ 31 let cacheCleaned = caches.keys().then((keys) => { 32 keys.forEach((key) => { 33 if (key !== pwacache) return caches.delete(key); 34 }); 35 }); 36 e.waitUntil(cacheCleaned); 37}); 38 39self.addEventListener('fetch', (e) => { 40 // serve from cache 41 if(!e.request.url.match(location.origin) || e.request.url.match('v5.htm') || e.request.url.match('feed.htm') || e.request.url.match('mnotify.htm') || e.request.url.match('notify.htm') || e.request.url.match('stats?')) return; 42 43 // cache with Network Fallback 44 let newRes = caches.open(pwacache).then((cache) => { 45 if(!e.request.url.match('static/c1e')){ 46 return fetch(e.request).then((fetchres)=>{ 47 if(fetchres){ 48 // Cache Fetched Response 49 if(e.request.url.indexOf('v5.htm')== -1 && e.request.url.indexOf('feed.htm')== -1 ){ 50 cache.put(e.request, fetchres.clone()) 51 } 52 return fetchres; 53 } 54 return cache.match(e.request).then((res)=>{ 55 // check cache response 56 if(res){ 57 console.log(`Serving ${res.url} from cache`); 58 return res; 59 } 60 }) 61 }) 62 } 63 return cache.match(e.request).then((res)=>{ 64 // check cache response 65 if(res){ 66 console.log(`Serving ${res.url} from cache`); 67 return res; 68 } 69 // Fallback to Network 70 return fetch(e.request).then((fetchres)=>{ 71 // Cache Fetched Response 72 if(e.request.url.indexOf('v5.htm')== -1 && e.request.url.indexOf('feed.htm')== -1 ){ 73 cache.put(e.request, fetchres.clone()) 74 } 75 return fetchres; 76 }) 77 }) 78 79 }) 80 e.respondWith(newRes); 81})
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.