110 строки
3.5 KiB
JavaScript
110 строки
3.5 KiB
JavaScript
/**
|
|
* Welcome to your Workbox-powered service worker!
|
|
*
|
|
* You'll need to register this file in your web app and you should
|
|
* disable HTTP caching for this file too.
|
|
* See https://goo.gl/nhQhGp
|
|
*
|
|
* The rest of the code is auto-generated. Please don't update this file
|
|
* directly; instead, make changes to your Workbox build configuration
|
|
* and re-run your build process.
|
|
* See https://goo.gl/2aRDsh
|
|
*/
|
|
|
|
importScripts("workbox-v3.6.3/workbox-sw.js");
|
|
workbox.setConfig({modulePathPrefix: "workbox-v3.6.3"});
|
|
|
|
workbox.core.setCacheNameDetails({prefix: "gatsby-plugin-offline"});
|
|
|
|
workbox.skipWaiting();
|
|
workbox.clientsClaim();
|
|
|
|
/**
|
|
* The workboxSW.precacheAndRoute() method efficiently caches and responds to
|
|
* requests for URLs in the manifest.
|
|
* See https://goo.gl/S9QRab
|
|
*/
|
|
self.__precacheManifest = [
|
|
{
|
|
"url": "webpack-runtime-eaa0f2dfc29d266f5c15.js"
|
|
},
|
|
{
|
|
"url": "commons.7be623a29cdf334e0cba.css"
|
|
},
|
|
{
|
|
"url": "commons-382e883493a00d179b6f.js"
|
|
},
|
|
{
|
|
"url": "app-71f90dee2e80ef8b8c99.js"
|
|
},
|
|
{
|
|
"url": "component---node-modules-gatsby-plugin-offline-app-shell-js-d2399568d871c4933ad4.js"
|
|
},
|
|
{
|
|
"url": "offline-plugin-app-shell-fallback/index.html",
|
|
"revision": "e5a47d8afd71f5a4e093e96e19101a2c"
|
|
},
|
|
{
|
|
"url": "page-data/offline-plugin-app-shell-fallback/page-data.json",
|
|
"revision": "c5c18bf0340c224bfa65408a3ab44f45"
|
|
},
|
|
{
|
|
"url": "manifest.webmanifest",
|
|
"revision": "5a64cd2d32e3dead92f54c5cad7103c9"
|
|
}
|
|
].concat(self.__precacheManifest || []);
|
|
workbox.precaching.suppressWarnings();
|
|
workbox.precaching.precacheAndRoute(self.__precacheManifest, {});
|
|
|
|
workbox.routing.registerRoute(/(\.js$|\.css$|static\/)/, workbox.strategies.cacheFirst(), 'GET');
|
|
workbox.routing.registerRoute(/^https?:.*\page-data\/.*\/page-data\.json/, workbox.strategies.networkFirst(), 'GET');
|
|
workbox.routing.registerRoute(/^https?:.*\.(png|jpg|jpeg|webp|svg|gif|tiff|js|woff|woff2|json|css)$/, workbox.strategies.staleWhileRevalidate(), 'GET');
|
|
workbox.routing.registerRoute(/^https?:\/\/fonts\.googleapis\.com\/css/, workbox.strategies.staleWhileRevalidate(), 'GET');
|
|
|
|
/* global importScripts, workbox, idbKeyval */
|
|
|
|
importScripts(`idb-keyval-iife.min.js`)
|
|
|
|
const { NavigationRoute } = workbox.routing
|
|
|
|
const navigationRoute = new NavigationRoute(async ({ event }) => {
|
|
let { pathname } = new URL(event.request.url)
|
|
pathname = pathname.replace(new RegExp(`^/flamegrill`), ``)
|
|
|
|
// Check for resources + the app bundle
|
|
// The latter may not exist if the SW is updating to a new version
|
|
const resources = await idbKeyval.get(`resources:${pathname}`)
|
|
if (!resources || !(await caches.match(`/flamegrill/app-71f90dee2e80ef8b8c99.js`))) {
|
|
return await fetch(event.request)
|
|
}
|
|
|
|
for (const resource of resources) {
|
|
// As soon as we detect a failed resource, fetch the entire page from
|
|
// network - that way we won't risk being in an inconsistent state with
|
|
// some parts of the page failing.
|
|
if (!(await caches.match(resource))) {
|
|
return await fetch(event.request)
|
|
}
|
|
}
|
|
|
|
const offlineShell = `/flamegrill/offline-plugin-app-shell-fallback/index.html`
|
|
return await caches.match(offlineShell)
|
|
})
|
|
|
|
workbox.routing.registerRoute(navigationRoute)
|
|
|
|
const messageApi = {
|
|
setPathResources(event, { path, resources }) {
|
|
event.waitUntil(idbKeyval.set(`resources:${path}`, resources))
|
|
},
|
|
|
|
clearPathResources(event) {
|
|
event.waitUntil(idbKeyval.clear())
|
|
},
|
|
}
|
|
|
|
self.addEventListener(`message`, event => {
|
|
const { gatsbyApi } = event.data
|
|
if (gatsbyApi) messageApi[gatsbyApi](event, event.data)
|
|
})
|