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