1importScripts('https://storage.googleapis.com/workbox-cdn/releases/7.0.0/workbox-sw.js'); 2 3if (workbox) { 4 workbox.setConfig({ debug: false }); 5 6 7 workbox.loadModule('workbox-expiration'); 8 workbox.loadModule('workbox-strategies'); 9 workbox.loadModule('workbox-cacheable-response'); 10 11 12 self.addEventListener('install', (event) => { 13 const urls = ['/offline.html']; 14 const cacheName = workbox.core.cacheNames.runtime; 15 event.waitUntil( 16 caches.open(cacheName).then((cache) => cache.addAll(urls)) 17 ); 18 self.skipWaiting(); 19 }); 20 21 self.addEventListener('activate', (event) => { 22 event.waitUntil(self.clients.claim()); 23 }); 24 25 26 const skipOpaquePlugin = { 27 cacheWillUpdate: async ({ response }) => { 28 if (!response || response.type === 'opaque') { 29 return null; 30 } 31 return response; 32 }, 33 }; 34 35 36 37 38 workbox.routing.registerRoute( 39 ({ url }) => 40 (url.pathname.endsWith('.js') || url.pathname === '/manifest.json') && 41 !url.hostname.includes('jsdelivr.net'), 42 new workbox.strategies.CacheFirst({ 43 cacheName: 'js-resources', 44 plugins: [ 45 skipOpaquePlugin, 46 47 new workbox.expiration.ExpirationPlugin({ 48 maxEntries: 50, 49 maxAgeSeconds: 15 * 24 * 60 * 60, // 15 days 50 }), 51 new workbox.cacheableResponse.CacheableResponsePlugin({ 52 statuses: [200], 53 }), 54 ], 55 }) 56 ); 57 58 59 workbox.routing.registerRoute( 60 ({ url }) => url.origin === 'https://fonts.gstatic.com', 61 new workbox.strategies.CacheFirst({ 62 cacheName: 'google-fonts', 63 plugins: [ 64 65 new workbox.expiration.ExpirationPlugin({ 66 maxEntries: 50, 67 maxAgeSeconds: 60 * 60 * 24 * 365, // 1 year 68 }), 69 new workbox.cacheableResponse.CacheableResponsePlugin({ 70 statuses: [0, 200] 71 }) 72 ] 73 }) 74 ); 75 76 77 workbox.routing.registerRoute( 78 ({ url }) => url.origin === 'https://t1.gstatic.com' && url.search.includes('FAVICON'), 79 new workbox.strategies.CacheFirst({ 80 cacheName: 'gstatic-content', 81 plugins: [ 82 83 new workbox.expiration.ExpirationPlugin({ 84 maxEntries: 2000, 85 maxAgeSeconds: 90 * 24 * 60 * 60, // 90 days 86 }), 87 new workbox.cacheableResponse.CacheableResponsePlugin({ 88 statuses: [0, 200] 89 }) 90 ] 91 }) 92 ); 93 94 95 workbox.routing.registerRoute( 96 ({ url }) => url.origin.endsWith('cdnpi.pe') && !url.pathname.endsWith('.mp4'), 97 new workbox.strategies.CacheFirst({ 98 cacheName: 'cdnpipe-assets', 99 plugins: [ 100 101 new workbox.expiration.ExpirationPlugin({ 102 maxEntries: 2000, 103 maxAgeSeconds: 90 * 24 * 60 * 60, 104 }), 105 new workbox.cacheableResponse.CacheableResponsePlugin({ 106 statuses: [0, 200], 107 }), 108 ], 109 }) 110 ); 111 112 113 workbox.routing.registerRoute( 114 ({ request }) => request.mode === 'navigate', 115 new workbox.strategies.NetworkFirst({ 116 cacheName: 'pages', 117 plugins: [ 118 119 new workbox.cacheableResponse.CacheableResponsePlugin({ 120 statuses: [200] 121 }) 122 ] 123 }) 124 ); 125 126 console.log('Workbox service worker loaded successfully'); 127} else { 128 console.error('Workbox failed to load'); 129}
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.