1const options = {"workboxURL":"https://cdn.jsdelivr.net/npm/[email protected]/workbox/workbox-sw.js","importScripts":["/sw/scripts/firebase-web-push.js"],"config":{"debug":false},"cacheOptions":{"cacheId":"app-prod","directoryIndex":"/","revision":"lpeHDWONmyiU"},"clientsClaim":true,"skipWaiting":true,"cleanupOutdatedCaches":true,"offlineAnalytics":false,"preCaching":[],"runtimeCaching":[{"urlPattern":"https://fonts.gstatic.com/.*","handler":"StaleWhileRevalidate","strategyOptions":{"cacheName":"fonts"},"strategyPlugins":[{"use":"cacheableResponse.CacheableResponsePlugin","config":[{"statuses":[200]}]}],"method":"GET"},{"urlPattern":"/_nuxt/","handler":"CacheFirst","method":"GET","strategyPlugins":[]},{"urlPattern":"/","handler":"NetworkFirst","method":"GET","strategyPlugins":[]}],"offlinePage":null,"pagesURLPattern":"/","offlineStrategy":"NetworkFirst"} 2 3const homePageCacheIndex = options.runtimeCaching.findIndex(({urlPattern}) => urlPattern === '/'); 4 5if (homePageCacheIndex > -1) { 6 options.runtimeCaching.splice(homePageCacheIndex, 1) 7} 8 9const nuxtDirCacheIndex = options.runtimeCaching.findIndex(({urlPattern}) => urlPattern === '/_nuxt/'); 10 11if (nuxtDirCacheIndex > -1) { 12 const isNetworkFirst = true 13 14 options.runtimeCaching.splice(nuxtDirCacheIndex, 1, { 15 urlPattern: "/_nuxt/(js|css|img|font|video)/.*", 16 handler: isNetworkFirst ? "NetworkFirst" : "CacheFirst", 17 method: "GET", 18 strategyPlugins: isNetworkFirst ? [] : [ 19 { 20 use: "cacheableResponse.CacheableResponsePlugin", 21 config: [ 22 { 23 statuses: [200] 24 } 25 ] 26 } 27 ] 28 }) 29} 30 31importScripts(...[options.workboxURL, ...options.importScripts]) 32 33initWorkbox(workbox, options) 34workboxExtensions(workbox, options) 35cachingExtensions(workbox, options) 36runtimeCaching(workbox, options) 37offlinePage(workbox, options) 38routingExtensions(workbox, options) 39 40function getProp(obj, prop) { 41 return prop.split('.').reduce((p, c) => p[c], obj) 42} 43 44function initWorkbox(workbox, options) { 45 if (options.config) { 46 // Set workbox config 47 workbox.setConfig(options.config) 48 } 49 50 if (options.cacheNames) { 51 // Set workbox cache names 52 workbox.core.setCacheNameDetails(options.cacheNames) 53 } 54 55 if (options.clientsClaim) { 56 // Start controlling any existing clients as soon as it activates 57 workbox.core.clientsClaim() 58 } 59 60 if (options.skipWaiting) { 61 workbox.core.skipWaiting() 62 } 63 64 if (options.cleanupOutdatedCaches) { 65 workbox.precaching.cleanupOutdatedCaches() 66 } 67 68 if (options.offlineAnalytics) { 69 // Enable offline Google Analytics tracking 70 workbox.googleAnalytics.initialize() 71 } 72} 73 74function runtimeCaching(workbox, options) { 75 const requestInterceptor = { 76 requestWillFetch({ request }) { 77 if (request.cache === 'only-if-cached' && request.mode === 'no-cors') { 78 return new Request(request.url, { ...request, cache: 'default', mode: 'no-cors' }) 79 } 80 return request 81 }, 82 fetchDidFail(ctx) { 83 ctx.error.message = 84 '[workbox] Network request for ' + ctx.request.url + ' threw an error: ' + ctx.error.message 85 // console.error(ctx.error, 'Details:', ctx) 86 }, 87 handlerDidError(ctx) { 88 ctx.error.message = 89 `[workbox] Network handler threw an error: ` + ctx.error.message 90 // console.error(ctx.error, 'Details:', ctx) 91 return null 92 } 93 } 94 95 for (const entry of options.runtimeCaching) { 96 const urlPattern = new RegExp(entry.urlPattern) 97 const method = entry.method || 'GET' 98 99 const plugins = (entry.strategyPlugins || []) 100 .map(p => { 101 return new (getProp(workbox, p.use))(...p.config) 102 }) 103 104 plugins.unshift(requestInterceptor) 105 106 const strategyOptions = { ...entry.strategyOptions, plugins } 107 108 const strategy = new workbox.strategies[entry.handler](strategyOptions) 109 110 workbox.routing.registerRoute(urlPattern, strategy, method) 111 } 112} 113 114function offlinePage(workbox, options) { 115 if (options.offlinePage) { 116 // Register router handler for offlinePage 117 workbox.routing.registerRoute(new RegExp(options.pagesURLPattern), ({ request, event }) => { 118 const strategy = new workbox.strategies[options.offlineStrategy] 119 return strategy 120 .handle({ request, event }) 121 .catch(() => caches.match(options.offlinePage)) 122 }) 123 } 124} 125 126function workboxExtensions(workbox, options) { 127 128} 129 130function cachingExtensions(workbox, options) { 131 132} 133
134function routingExtensions(workbox, options) { 135 136}
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.