-
Notifications
You must be signed in to change notification settings - Fork 0
/
sw.js
41 lines (37 loc) · 1.1 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
import "babel-polyfill";
import toolbox from "./node_modules/sw-toolbox/sw-toolbox";
toolbox.precache(["fail.html"]);
toolbox.router.get("/(.*)", function(request, values, options) {
return toolbox.networkFirst(request, values, options).catch(function(error) {
if (
request.method === "GET" &&
request.headers.get("accept").includes("text/html")
) {
return toolbox.cacheOnly(new Request("dist/fail.html"), values, options);
}
throw error;
});
});
// addEventListener("install", event => {
// skipWaiting();
// // prettier-ignore
// event.waitUntil(
// async function() {
// const cache = await caches.open("static");
// await cache.addAll(["fail.html", "/"]);
// }());
// });
// addEventListener("fetch", event => {
// event.respondWith(
// // prettier-ignore
// async function() {
// const cachedRes = await caches.match(event.request);
// if (cachedRes) return cachedRes;
// try {
// return await fetch(event.request);
// } catch (err) {
// return caches.match("static");
// }
// }()
// );
// });