-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsw.js
More file actions
65 lines (62 loc) · 1.95 KB
/
Copy pathsw.js
File metadata and controls
65 lines (62 loc) · 1.95 KB
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
/* Minimal shell cache for Null-X dashboard */
var CACHE = "nx-shell-v1";
var SHELL = [
"/",
"/index.html",
"/Newhomepage/index.html",
"/Newhomepage/newpage.css",
"/CSS/style.css",
"/JS/nx-ux.js",
"/CSS/nx-ux.css",
"/version.json"
];
self.addEventListener("install", function (event) {
event.waitUntil(
caches.open(CACHE).then(function (cache) {
return cache.addAll(SHELL.map(function (u) {
return new Request(u, { cache: "reload" });
})).catch(function () {});
}).then(function () { return self.skipWaiting(); })
);
});
self.addEventListener("activate", function (event) {
event.waitUntil(
caches.keys().then(function (keys) {
return Promise.all(keys.filter(function (k) { return k !== CACHE; }).map(function (k) { return caches.delete(k); }));
}).then(function () { return self.clients.claim(); })
);
});
self.addEventListener("fetch", function (event) {
var req = event.request;
if (req.method !== "GET") return;
var url = new URL(req.url);
if (url.origin !== self.location.origin) return;
if (req.mode === "navigate") {
event.respondWith(
fetch(req).then(function (res) {
var copy = res.clone();
caches.open(CACHE).then(function (c) { c.put(req, copy); });
return res;
}).catch(function () {
return caches.match(req).then(function (r) {
return r || caches.match("/Newhomepage/index.html") || caches.match("/index.html");
});
})
);
return;
}
if (/\.(css|js|svg|png|woff2)$/i.test(url.pathname) || url.pathname === "/version.json") {
event.respondWith(
caches.match(req).then(function (hit) {
var fetcher = fetch(req).then(function (res) {
if (res && res.ok) {
var copy = res.clone();
caches.open(CACHE).then(function (c) { c.put(req, copy); });
}
return res;
}).catch(function () { return hit; });
return hit || fetcher;
})
);
}
});