1var staticCacheName = "pwa-v" + new Date().getTime(); 2 3if (!filesToCache){ 4 var filesToCache = [ 5 '/offline', 6 // Vapor.asset('/css/app.css'), 7 // Vapor.asset('/js/app.js'), 8 //'/images/icons/icon-72x72.png', 9 //'/images/icons/icon-96x96.png', 10 //'/images/icons/icon-128x128.png', 11 //'/images/icons/icon-144x144.png', 12 //'/images/icons/icon-152x152.png', 13 //'/images/icons/icon-192x192.png', 14 //'/images/icons/icon-384x384.png', 15 //'/images/icons/icon-512x512.png', 16 ]; 17} 18 19// Cache on install 20self.addEventListener("install", event => { 21 this.skipWaiting(); 22 event.waitUntil( 23 caches.open(staticCacheName) 24 .then(cache => { 25 return cache.addAll(filesToCache); 26 }) 27 ) 28}); 29 30// Clear cache on activate 31self.addEventListener('activate', event => { 32 event.waitUntil( 33 caches.keys().then(cacheNames => { 34 return Promise.all( 35 cacheNames 36 .filter(cacheName => (cacheName.startsWith("pwa-"))) 37 .filter(cacheName => (cacheName !== staticCacheName)) 38 .map(cacheName => caches.delete(cacheName)) 39 ); 40 }) 41 ); 42}); 43 44// Serve from Cache 45self.addEventListener("fetch", event => { 46 try { 47 // Only handle GET requests. 48 if (event.request.method !== 'GET') return; 49 50 // Do NOT intercept cross-origin requests (e.g. Google Tag Manager). 51 // If those fail (blocked by client / offline), we should not serve our HTML offline page as JS. 52 var url = new URL(event.request.url); 53 if (url.origin !== self.location.origin) return; 54 } catch (e) { 55 // If URL parsing fails for any reason, fall back to default network behavior. 56 return; 57 } 58 59 event.respondWith( 60 caches.match(event.request) 61 .then(response => response || fetch(event.request)) 62 .catch(() => { 63 // Only serve the offline page for document navigations. 64 if (event.request.mode === 'navigate') { 65 return caches.match('/offline'); 66 } 67 // For non-navigation requests, let the request fail normally. 68 return Response.error(); 69 }) 70 ); 71});
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.