1var staticCacheName = "pwa-v" + new Date().getTime(); 2var filesToCache = [ 3 '/offline', 4 '/build/css/app.css', 5 '/build/js/vendor/vendor.js', 6 '/build/js/app.js', 7 '/images/icons/icon-72x72.png', 8 '/images/icons/icon-96x96.png', 9 '/images/icons/icon-128x128.png', 10 '/images/icons/icon-144x144.png', 11 '/images/icons/icon-152x152.png', 12 '/images/icons/icon-192x192.png', 13 '/images/icons/icon-384x384.png', 14 '/images/icons/icon-512x512.png', 15]; 16 17// Cache on install 18self.addEventListener("install", event => { 19 this.skipWaiting(); 20 event.waitUntil( 21 caches.open(staticCacheName) 22 .then(cache => { 23 return cache.addAll(filesToCache); 24 }) 25 ) 26}); 27 28// Clear cache on activate 29self.addEventListener('activate', event => { 30 event.waitUntil( 31 caches.keys().then(cacheNames => { 32 return Promise.all( 33 cacheNames 34 .filter(cacheName => (cacheName.startsWith("pwa-"))) 35 .filter(cacheName => (cacheName !== staticCacheName)) 36 .map(cacheName => caches.delete(cacheName)) 37 ); 38 }) 39 ); 40}); 41 42// Serve from Cache 43self.addEventListener("fetch", event => { 44 event.respondWith( 45 caches.match(event.request) 46 .then(response => { 47 return response || fetch(event.request); 48 }) 49 .catch(() => { 50 return caches.match('offline'); 51 }) 52 ) 53});
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.