1/** 2 * Welcome to your Workbox-powered service worker! 3 * 4 * You'll need to register this file in your web app and you should 5 * disable HTTP caching for this file too. 6 * See https://goo.gl/nhQhGp 7 * 8 * The rest of the code is auto-generated. Please don't update this file 9 * directly; instead, make changes to your Workbox build configuration 10 * and re-run your build process. 11 * See https://goo.gl/2aRDsh 12 */ 13 14importScripts("workbox-v4.3.1/workbox-sw.js"); 15workbox.setConfig({modulePathPrefix: "workbox-v4.3.1"}); 16 17workbox.core.setCacheNameDetails({prefix: "gatsby-plugin-offline"}); 18 19workbox.core.skipWaiting(); 20 21workbox.core.clientsClaim(); 22 23/** 24 * The workboxSW.precacheAndRoute() method efficiently caches and responds to 25 * requests for URLs in the manifest. 26 * See https://goo.gl/S9QRab 27 */ 28self.__precacheManifest = [ 29 { 30 "url": "webpack-runtime-a1fa4a8e28b9eea05f17.js" 31 }, 32 { 33 "url": "framework-d8a3cbdb311c339c1233.js" 34 }, 35 { 36 "url": "app-a3eabccdddb88ad62513.js" 37 }, 38 { 39 "url": "offline-plugin-app-shell-fallback/index.html", 40 "revision": "cb31e25148a638f4505b9ca1d710c27f" 41 }, 42 { 43 "url": "component---cache-caches-gatsby-plugin-offline-app-shell-js-16a8b689b8814701a863.js" 44 }, 45 { 46 "url": "manifest.webmanifest", 47 "revision": "c8d93ebcfeb9b87e54bd26fdac98d817" 48 } 49].concat(self.__precacheManifest || []); 50workbox.precaching.precacheAndRoute(self.__precacheManifest, {}); 51 52workbox.routing.registerRoute(/^https?:\/\/fonts\.gstatic\.com\//, new workbox.strategies.CacheFirst({ "cacheName":"google-fonts-webfonts", plugins: [new workbox.expiration.Plugin({ maxAgeSeconds: 31536000, maxEntries: 30, purgeOnQuotaError: false }), new workbox.cacheableResponse.Plugin({ statuses: [ 200 ] })] }), 'GET'); 53workbox.routing.registerRoute(/(\.js$|\.css$|static\/)/, new workbox.strategies.CacheFirst(), 'GET'); 54workbox.routing.registerRoute(/^https?:.*\/page-data\/.*\.json$/, new workbox.strategies.NetworkFirst({ "networkTimeoutSeconds":10, plugins: [] }), 'GET'); 55workbox.routing.registerRoute(/^https?:.*\.(png|jpg|jpeg|webp|svg|gif|tiff|js|woff|woff2|json|css)$/, new workbox.strategies.StaleWhileRevalidate(), 'GET'); 56workbox.routing.registerRoute(/^https?:\/\/fonts\.googleapis\.com\/css/, new workbox.strategies.StaleWhileRevalidate(), 'GET'); 57workbox.routing.registerRoute(/\/$/, new workbox.strategies.NetworkFirst({ "networkTimeoutSeconds":10, plugins: [] }), 'GET'); 58 59/* global importScripts, workbox, idbKeyval */ 60importScripts(`idb-keyval-3.2.0-iife.min.js`) 61 62const { NavigationRoute } = workbox.routing 63 64let lastNavigationRequest = null 65let offlineShellEnabled = true 66 67// prefer standard object syntax to support more browsers 68const MessageAPI = { 69 setPathResources: (event, { path, resources }) => { 70 event.waitUntil(idbKeyval.set(`resources:${path}`, resources)) 71 }, 72 73 clearPathResources: event => { 74 event.waitUntil(idbKeyval.clear()) 75 }, 76 77 enableOfflineShell: () => { 78 offlineShellEnabled = true 79 }, 80 81 disableOfflineShell: () => { 82 offlineShellEnabled = false 83 }, 84} 85 86self.addEventListener(`message`, event => { 87 const { gatsbyApi: api } = event.data 88 if (api) MessageAPI[api](event, event.data) 89}) 90 91function handleAPIRequest({ event }) { 92 const { pathname } = new URL(event.request.url) 93 94 const params = pathname.match(/:(.+)/)[1] 95 const data = {} 96 97 if (params.includes(`=`)) { 98 params.split(`&`).forEach(param => { 99 const [key, val] = param.split(`=`) 100 data[key] = val 101 }) 102 } else { 103 data.api = params 104 } 105 106 if (MessageAPI[data.api] !== undefined) { 107 MessageAPI[data.api]() 108 } 109 110 if (!data.redirect) { 111 return new Response() 112 } 113 114 return new Response(null, { 115 status: 302, 116 headers: { 117 Location: lastNavigationRequest, 118 }, 119 }) 120} 121 122const navigationRoute = new NavigationRoute(async ({ event }) => { 123 // handle API requests separately to normal navigation requests, so do this 124 // check first 125 if (event.request.url.match(/\/.gatsby-plugin-offline:.+/)) { 126 return handleAPIRequest({ event }) 127 } 128 129 if (!offlineShellEnabled) { 130 return await fetch(event.request) 131 } 132 133 lastNavigationRequest = event.request.url 134 135 let { pathname } = new URL(event.request.url) 136 pathname = pathname.replace(new RegExp(`^`), ``) 137 138 // Check for resources + the app bundle 139 // The latter may not exist if the SW is updating to a new version 140 const resources = await idbKeyval.get(`resources:${pathname}`) 141 if (!resources || !(await caches.match(`/app-a3eabccdddb88ad62513.js`))) { 142 return await fetch(event.request) 143 } 144 145 for (const resource of resources) { 146 // As soon as we detect a failed resource, fetch the entire page from 147 // network - that way we won't risk being in an inconsistent state with 148 // some parts of the page failing. 149 if (!(await caches.match(resource))) { 150 return await fetch(event.request) 151 } 152 } 153 154 const offlineShell = `/offline-plugin-app-shell-fallback/index.html` 155 const offlineShellWithKey = workbox.precaching.getCacheKeyForURL(offlineShell) 156 return await caches.match(offlineShellWithKey) 157}) 158 159workbox.routing.registerRoute(navigationRoute) 160 161// this route is used when performing a non-navigation request (e.g. fetch) 162workbox.routing.registerRoute(/\/.gatsby-plugin-offline:.+/, handleAPIRequest)
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.