1importScripts('https://storage.googleapis.com/workbox-cdn/releases/6.1.1/workbox-sw.js'); 2// Cache page navigations (html) with a Network First strategy 3// workbox.setConfig({ 4// debug: true, 5// }); 6workbox.loadModule('workbox-routing'); 7workbox.loadModule('workbox-strategies'); 8workbox.loadModule('workbox-cacheable-response'); 9workbox.loadModule('workbox-expiration'); 10workbox.loadModule('workbox-precaching'); 11//workbox.loadModule('workbox-recipes'); 12 13 14 15const {registerRoute,setCatchHandler} = workbox.routing; 16const {NetworkFirst,StaleWhileRevalidate,CacheFirst} = workbox.strategies; 17const {CacheableResponsePlugin} = workbox.cacheableResponse; 18const {ExpirationPlugin} = workbox.expiration; 19const {precacheAndRoute,matchPrecache} = workbox.precaching; 20//const {offlineFallback} = workbox.recipes; 21 22 23// offlineFallback(); 24 25// precacheAndRoute([ 26// {url: '/', revision: 1 } 27// ]); 28 29// Catch routing errors, like if the user is offline 30setCatchHandler(async ({ event }) => { 31 // Return the precached offline page if a document is being requested 32 if (event.request.destination === 'document') { 33 return matchPrecache('/offline.html'); 34 } 35 36 return Response.error(); 37}); 38self.addEventListener('install', e => { 39 self.skipWaiting(); 40}); 41 42//Cache page navigations (html) with a Network First strategy 43// registerRoute( 44// //({url}) => url.origin === 'https://www.indiaweather24.com/', 45// // Check to see if the request is a navigation to a new page 46// ({ request }) => request.mode === 'navigate', 47// // Use a Network First caching strategy 48// new NetworkFirst({ 49// // Put all cached files in a cache named 'pages' 50// cacheName: 'pages', 51// plugins: [ 52// // Ensure that only requests that result in a 200 status are cached 53// new CacheableResponsePlugin({ 54// statuses: [200], 55// }), 56// ], 57// }), 58// ); 59 60// Cache CSS, JS, and Web Worker requests with a Stale While Revalidate strategy 61registerRoute( 62 // Check to see if the request's destination is style for stylesheets, script for JavaScript, or worker for web worker 63 ({ request }) => 64 request.destination === 'style' || 65 request.destination === 'script' || 66 67 request.destination === 'worker', 68 // Use a Stale While Revalidate caching strategy 69 new StaleWhileRevalidate({ 70 // Put all cached files in a cache named 'assets' 71 cacheName: 'assets', 72 plugins: [ 73 // Ensure that only requests that result in a 200 status are cached 74 new CacheableResponsePlugin({ 75 statuses: [200], 76 }), 77 ], 78 }), 79); 80 81// Cache images with a Cache First strategy 82registerRoute( 83 // Check to see if the request's destination is style for an image 84 ({ request }) => request.destination === 'image' || request.destination === 'font', 85 86 // Use a Cache First caching strategy 87 new CacheFirst({ 88 // Put all cached files in a cache named 'images' 89 cacheName: 'images', 90 plugins: [ 91 // Ensure that only requests that result in a 200 status are cached 92 new CacheableResponsePlugin({ 93 statuses: [200], 94 }), 95 // Don't cache more than 50 items, and expire them after 30 days 96 new ExpirationPlugin({ 97 maxEntries: 50, 98 maxAgeSeconds: 60 * 60 * 24 * 30, // 30 Days 99 }), 100 ], 101 }), 102); 103 104 105 106
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.