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