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-30c5701fa25cd86f87d3.js" 31 }, 32 { 33 "url": "styles.d4b7690add9296f424c3.css" 34 }, 35 { 36 "url": "framework-59ec755b5c273d6e407a.js" 37 }, 38 { 39 "url": "app-b54735219c2c693b101e.js" 40 }, 41 { 42 "url": "offline-plugin-app-shell-fallback/index.html", 43 "revision": "5bfb51f7f988ab4a91fd12b06a5fdf6a" 44 }, 45 { 46 "url": "manifest.json", 47 "revision": "b58fcfa7628c9205cb11a1b2c3e8f99a" 48 }, 49 { 50 "url": "manifest.webmanifest", 51 "revision": "8c5b6115cb959fb063e62e89dd12b144" 52 } 53].concat(self.__precacheManifest || []); 54workbox.precaching.precacheAndRoute(self.__precacheManifest, {}); 55 56workbox.routing.registerRoute(/(\.js$|\.css$|static\/)/, new workbox.strategies.CacheFirst(), 'GET'); 57workbox.routing.registerRoute(/^https?:.*\/page-data\/.*\.json/, new workbox.strategies.StaleWhileRevalidate(), 'GET'); 58workbox.routing.registerRoute(/^https?:.*\.(png|jpg|jpeg|webp|avif|svg|gif|tiff|js|woff|woff2|json|css)$/, new workbox.strategies.StaleWhileRevalidate(), 'GET'); 59workbox.routing.registerRoute(/^https?:\/\/fonts\.googleapis\.com\/css/, new workbox.strategies.StaleWhileRevalidate(), 'GET'); 60 61/* global importScripts, workbox, idbKeyval */ 62importScripts(`idb-keyval-3.2.0-iife.min.js`) 63 64const { NavigationRoute } = workbox.routing 65 66let lastNavigationRequest = null 67let offlineShellEnabled = true 68 69// prefer standard object syntax to support more browsers 70const MessageAPI = { 71 setPathResources: (event, { path, resources }) => { 72 event.waitUntil(idbKeyval.set(`resources:${path}`, resources)) 73 }, 74 75 clearPathResources: event => { 76 event.waitUntil(idbKeyval.clear()) 77 78 // We detected compilation hash mismatch 79 // we should clear runtime cache as data 80 // files might be out of sync and we should 81 // do fresh fetches for them 82 event.waitUntil( 83 caches.keys().then(function (keyList) { 84 return Promise.all( 85 keyList.map(function (key) { 86 if (key && key.includes(`runtime`)) { 87 return caches.delete(key) 88 } 89 90 return Promise.resolve() 91 }) 92 ) 93 }) 94 ) 95 }, 96 97 enableOfflineShell: () => { 98 offlineShellEnabled = true 99 }, 100 101 disableOfflineShell: () => { 102 offlineShellEnabled = false 103 }, 104} 105 106self.addEventListener(`message`, event => { 107 const { gatsbyApi: api } = event.data 108 if (api) MessageAPI[api](event, event.data) 109}) 110 111function handleAPIRequest({ event }) { 112 const { pathname } = new URL(event.request.url) 113 114 const params = pathname.match(/:(.+)/)[1] 115 const data = {} 116 117 if (params.includes(`=`)) { 118 params.split(`&`).forEach(param => { 119 const [key, val] = param.split(`=`) 120 data[key] = val 121 }) 122 } else { 123 data.api = params 124 } 125 126 if (MessageAPI[data.api] !== undefined) { 127 MessageAPI[data.api]() 128 } 129 130 if (!data.redirect) { 131 return new Response() 132 } 133 134 return new Response(null, { 135 status: 302, 136 headers: { 137 Location: lastNavigationRequest, 138 }, 139 }) 140} 141 142const navigationRoute = new NavigationRoute(async ({ event }) => { 143 // handle API requests separately to normal navigation requests, so do this 144 // check first 145 if (event.request.url.match(/\/.gatsby-plugin-offline:.+/)) { 146 return handleAPIRequest({ event }) 147 } 148 149 if (!offlineShellEnabled) { 150 return await fetch(event.request) 151 } 152 153 lastNavigationRequest = event.request.url 154 155 let { pathname } = new URL(event.request.url) 156 pathname = pathname.replace(new RegExp(`^`), ``) 157 158 // Check for resources + the app bundle 159 // The latter may not exist if the SW is updating to a new version 160 const resources = await idbKeyval.get(`resources:${pathname}`) 161 if (!resources || !(await caches.match(`/app-b54735219c2c693b101e.js`))) { 162 return await fetch(event.request) 163 } 164 165 for (const resource of resources) { 166 // As soon as we detect a failed resource, fetch the entire page from 167 // network - that way we won't risk being in an inconsistent state with 168 // some parts of the page failing. 169 if (!(await caches.match(resource))) { 170 return await fetch(event.request) 171 } 172 } 173 174 const offlineShell = `/offline-plugin-app-shell-fallback/index.html` 175 const offlineShellWithKey = workbox.precaching.getCacheKeyForURL(offlineShell) 176 return await caches.match(offlineShellWithKey) 177}) 178 179workbox.routing.registerRoute(navigationRoute) 180 181// this route is used when performing a non-navigation request (e.g. fetch) 182workbox.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.