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