1importScripts( 2 'https://storage.googleapis.com/workbox-cdn/releases/5.0.0/workbox-sw.js' 3) 4 5workbox.core.setCacheNameDetails({ 6 // This allows you to work on multiple projects using 7 // the same localhost port number without mixing up the caches. 8 prefix: 'on', 9}) 10 11// Cache the Google Fonts stylesheets with a stale-while-revalidate strategy. 12workbox.routing.registerRoute( 13 /^https:\/\/fonts\.googleapis\.com/, 14 new workbox.strategies.StaleWhileRevalidate({ 15 cacheName: 'google-fonts-stylesheets', 16 }) 17) 18 19// Cache the underlying font files with a cache-first strategy for 1 year. 20workbox.routing.registerRoute( 21 /^https:\/\/fonts\.gstatic\.com/, 22 new workbox.strategies.CacheFirst({ 23 cacheName: 'google-fonts-webfonts', 24 plugins: [ 25 new workbox.cacheableResponse.CacheableResponsePlugin({ 26 statuses: [0, 200], 27 }), 28 new workbox.expiration.ExpirationPlugin({ 29 maxAgeSeconds: 60 * 60 * 24 * 365, 30 maxEntries: 30, 31 }), 32 ], 33 }) 34) 35 36// Cache images with a cache-first strategy for 30 days 37workbox.routing.registerRoute( 38 /\.*(?:png|gif|jpg|jpeg|webp|svg)$/, 39 new workbox.strategies.CacheFirst({ 40 cacheName: 'images', 41 plugins: [ 42 new workbox.expiration.ExpirationPlugin({ 43 maxEntries: 60, 44 maxAgeSeconds: 30 * 24 * 60 * 60, // 30 Days 45 }), 46 ], 47 }) 48) 49 50workbox.routing.registerRoute( 51 /\.*(?:js|css)$/, 52 new workbox.strategies.StaleWhileRevalidate({ 53 cacheName: 'static-resources', 54 }) 55) 56 57self.addEventListener('message', event => { 58 switch (event.data) { 59 case 'skipWaiting': 60 // Console.log('self.skipWaiting()'); 61 self.skipWaiting() 62 // We don't call claim as it would be too strong. 63 // Instead of controlling the page after it was loaded. 64 // We wait for the activated event to reload the page and have the 65 // activated service worker control it. 66 // self.clients.claim(); 67 break 68 default: 69 break 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.