/
sw.js
149 lines (132 loc) Β· 4.53 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/**
* 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-eaaf926844eed8cc7472.js"
},
{
"url": "app-a5062fccc948e5c0a82c.js"
},
{
"url": "component---node-modules-gatsby-plugin-offline-app-shell-js-254be6d36119a5d82b71.js"
},
{
"url": "offline-plugin-app-shell-fallback/index.html",
"revision": "1c4d1011e597a1767a61f009f44f7135"
},
{
"url": "static/d/520/path---offline-plugin-app-shell-fallback-a-30-c5a-NZuapzHg3X9TaN1iIixfv1W23E.json",
"revision": "c2508676a2f33ea9f1f0bf472997f9a0"
},
{
"url": "manifest.json",
"revision": "5dfb23ee0bf2cf44a94105922a35e433"
},
{
"url": "manifest.webmanifest",
"revision": "2d9ae97ddeade4be8b7dcac7873511e1"
}
].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?:.*\.(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');
"use strict";
/* global importScripts, workbox, idbKeyval */
importScripts("idb-keyval-iife.min.js");
var WHITELIST_KEY = "custom-navigation-whitelist";
var navigationRoute = new workbox.routing.NavigationRoute(function (_ref) {
var event = _ref.event;
var _ref2 = new URL(event.request.url),
pathname = _ref2.pathname;
return idbKeyval.get(WHITELIST_KEY).then(function (customWhitelist) {
if (customWhitelist === void 0) {
customWhitelist = [];
}
// Respond with the offline shell if we match the custom whitelist
if (customWhitelist.includes(pathname)) {
var offlineShell = "/offline-plugin-app-shell-fallback/index.html";
var cacheName = workbox.core.cacheNames.precache;
return caches.match(offlineShell, {
cacheName: cacheName
});
}
return fetch(event.request);
});
});
workbox.routing.registerRoute(navigationRoute);
var updatingWhitelist = null;
function rawWhitelistPathnames(pathnames) {
if (updatingWhitelist !== null) {
// Prevent the whitelist from being updated twice at the same time
return updatingWhitelist.then(function () {
return rawWhitelistPathnames(pathnames);
});
}
updatingWhitelist = idbKeyval.get(WHITELIST_KEY).then(function (customWhitelist) {
if (customWhitelist === void 0) {
customWhitelist = [];
}
pathnames.forEach(function (pathname) {
if (!customWhitelist.includes(pathname)) customWhitelist.push(pathname);
});
return idbKeyval.set(WHITELIST_KEY, customWhitelist);
}).then(function () {
updatingWhitelist = null;
});
return updatingWhitelist;
}
function rawResetWhitelist() {
if (updatingWhitelist !== null) {
return updatingWhitelist.then(function () {
return rawResetWhitelist();
});
}
updatingWhitelist = idbKeyval.set(WHITELIST_KEY, []).then(function () {
updatingWhitelist = null;
});
return updatingWhitelist;
}
var messageApi = {
whitelistPathnames: function whitelistPathnames(event) {
var pathnames = event.data.pathnames;
pathnames = pathnames.map(function (_ref3) {
var pathname = _ref3.pathname,
includesPrefix = _ref3.includesPrefix;
if (!includesPrefix) {
return "" + pathname;
} else {
return pathname;
}
});
event.waitUntil(rawWhitelistPathnames(pathnames));
},
resetWhitelist: function resetWhitelist(event) {
event.waitUntil(rawResetWhitelist());
}
};
self.addEventListener("message", function (event) {
var gatsbyApi = event.data.gatsbyApi;
if (gatsbyApi) messageApi[gatsbyApi](event);
});