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-efc90e5404b2905f7433.js" 31 }, 32 { 33 "url": "framework-4adb46e364577e67729f.js" 34 }, 35 { 36 "url": "app-bc207999cb8dab147a5c.js" 37 }, 38 { 39 "url": "offline-plugin-app-shell-fallback/index.html", 40 "revision": "863f073362487591768b11a16242259a" 41 }, 42 { 43 "url": "component---cache-caches-gatsby-plugin-offline-app-shell-js-b1462017a2c34a95e2b4.js" 44 }, 45 { 46 "url": "manifest.webmanifest", 47 "revision": "9b07b85d484a8f1b9982031dff59ea27" 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.StaleWhileRevalidate(), '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'); 56 57/* global importScripts, workbox, idbKeyval */ 58 59importScripts(`idb-keyval-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 76 enableOfflineShell: () => { 77 offlineShellEnabled = true 78 }, 79 80 disableOfflineShell: () => { 81 offlineShellEnabled = false 82 }, 83} 84 85self.addEventListener(`message`, event => { 86 const { gatsbyApi: api } = event.data 87 if (api) MessageAPI[api](event, event.data) 88}) 89 90function handleAPIRequest({ event }) { 91 const { pathname } = new URL(event.request.url) 92 93 const params = pathname.match(/:(.+)/)[1] 94 const data = {} 95 96 if (params.includes(`=`)) { 97 params.split(`&`).forEach(param => { 98 const [key, val] = param.split(`=`) 99 data[key] = val 100 }) 101 } else { 102 data.api = params 103 } 104 105 if (MessageAPI[data.api] !== undefined) { 106 MessageAPI[data.api]() 107 } 108 109 if (!data.redirect) { 110 return new Response() 111 } 112 113 return new Response(null, { 114 status: 302, 115 headers: { 116 Location: lastNavigationRequest, 117 }, 118 }) 119} 120 121const navigationRoute = new NavigationRoute(async ({ event }) => { 122 // handle API requests separately to normal navigation requests, so do this 123 // check first 124 if (event.request.url.match(/\/.gatsby-plugin-offline:.+/)) { 125 return handleAPIRequest({ event }) 126 } 127 128 if (!offlineShellEnabled) { 129 return await fetch(event.request) 130 } 131 132 lastNavigationRequest = event.request.url 133 134 let { pathname } = new URL(event.request.url) 135 pathname = pathname.replace(new RegExp(`^`), ``) 136 137 // Check for resources + the app bundle 138 // The latter may not exist if the SW is updating to a new version 139 const resources = await idbKeyval.get(`resources:${pathname}`) 140 if (!resources || !(await caches.match(`/app-bc207999cb8dab147a5c.js`))) { 141 return await fetch(event.request) 142 } 143 144 for (const resource of resources) { 145 // As soon as we detect a failed resource, fetch the entire page from 146 // network - that way we won't risk being in an inconsistent state with 147 // some parts of the page failing. 148 if (!(await caches.match(resource))) { 149 return await fetch(event.request) 150 } 151 } 152 153 const offlineShell = `/offline-plugin-app-shell-fallback/index.html` 154 const offlineShellWithKey = workbox.precaching.getCacheKeyForURL(offlineShell) 155 return await caches.match(offlineShellWithKey) 156}) 157 158workbox.routing.registerRoute(navigationRoute) 159 160// this route is used when performing a non-navigation request (e.g. fetch) 161workbox.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.