-
Notifications
You must be signed in to change notification settings - Fork 0
/
sw.js
118 lines (102 loc) · 3.61 KB
/
sw.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/**
* 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-d83bf291c798d1e776d0.js"
},
{
"url": "styles.f0ecd3c826377831322f.css"
},
{
"url": "styles-89fd2ae28bdf06750a71.js"
},
{
"url": "framework-88141e8bb2fa5a1effff.js"
},
{
"url": "532a2f07-b004a5d2f37fbac8de1a.js"
},
{
"url": "app-ffbdeab4004711c9fd0f.js"
},
{
"url": "component---node-modules-gatsby-plugin-offline-app-shell-js-a6a66bbf02bb8377a480.js"
},
{
"url": "offline-plugin-app-shell-fallback/index.html",
"revision": "328e252be24979e59dc403db6ab63edb"
},
{
"url": "polyfill-d43973584172f46ef21f.js"
},
{
"url": "manifest.json",
"revision": "525f8fdc673f544887998e2e653a54c5"
},
{
"url": "manifest.webmanifest",
"revision": "80a826c97f79d83f9ea1a867bcb7f878"
}
].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(`^`), ``)
// 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(`/app-ffbdeab4004711c9fd0f.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 = `/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)
})