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