-
Notifications
You must be signed in to change notification settings - Fork 0
/
sw.js
35 lines (31 loc) · 982 Bytes
/
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
self.importScripts(
"https://cdnjs.cloudflare.com/ajax/libs/sw-toolbox/3.6.1/sw-toolbox.js"
);
self.toolbox.precache([
"/",
"/main.js",
"/theme-toggle.js",
"/main.css",
"https://cdnjs.cloudflare.com/ajax/libs/skeleton/2.0.4/skeleton.min.css",
"https://cdnjs.cloudflare.com/ajax/libs/sw-toolbox/3.6.1/sw-toolbox.js",
]);
self.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("/"), values, options);
}
throw error;
});
});
// sw activated
self.addEventListener("activate", function (event) {
// claims the sw for client after wait skipped
return self.clients.claim();
});
self.addEventListener("install", (event) => {
// skip wait to install a new version of service worker
self.skipWaiting();
});