1try { 2 run(); 3} catch (e) { 4 console.warn('Workbox not supported'); 5} 6 7function run() { 8 importScripts('https://storage.googleapis.com/workbox-cdn/releases/7.1.0/workbox-sw.js'); 9 const { clientsClaim } = workbox.core; 10 11 self.skipWaiting(); 12 clientsClaim(); 13 14 cacheFirst({ 15 destination: 'style', 16 maxAgeSeconds: 432000, 17 maxEntries: 50, 18 }); 19 20 cacheFirst({ 21 destination: 'script', 22 maxAgeSeconds: 432000, 23 maxEntries: 50, 24 }); 25 26 cacheFirst({ 27 destination: 'image', 28 maxAgeSeconds: 432000, 29 maxEntries: 240, 30 }); 31 32 cacheFirst({ 33 destination: 'font', 34 maxAgeSeconds: 31536000, 35 maxEntries: 10, 36 }); 37} 38 39function cacheFirst({ destination, maxEntries, maxAgeSeconds }) { 40 const { CacheFirst } = workbox.strategies; 41 const { CacheableResponsePlugin } = workbox.cacheableResponse; 42 const { ExpirationPlugin } = workbox.expiration; 43 const { registerRoute } = workbox.routing; 44 const allowedOrigins = ['https://cdn.businessinsider.com.pl']; 45 46 registerRoute( 47 ({ request, url }) => request.destination === destination && allowedOrigins.includes(url.origin), 48 new CacheFirst({ 49 cacheName: `static-${destination}`, 50 fetchOptions: { 51 mode: 'cors', 52 credentials: 'same-origin', 53 }, 54 plugins: [ 55 new CacheableResponsePlugin({ statuses: [200] }), 56 new ExpirationPlugin({ maxEntries, maxAgeSeconds }), 57 ], 58 }), 59 ); 60}
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.