-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathservice-worker.js
More file actions
43 lines (38 loc) · 1.14 KB
/
Copy pathservice-worker.js
File metadata and controls
43 lines (38 loc) · 1.14 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
const CACHE_NAME = "browser-sop-builder-v4";
const APP_SHELL = [
"./",
"./index.html",
"./sop-builder.js",
"./manifest.webmanifest",
"./app-icon.svg",
"./sop-service-cover.png"
];
self.addEventListener("install", (event) => {
event.waitUntil(caches.open(CACHE_NAME).then((cache) => cache.addAll(APP_SHELL)));
self.skipWaiting();
});
self.addEventListener("activate", (event) => {
event.waitUntil(
caches.keys().then((keys) =>
Promise.all(
keys
.filter((key) => key.startsWith("browser-sop-builder-") && key !== CACHE_NAME)
.map((key) => caches.delete(key))
)
)
);
self.clients.claim();
});
self.addEventListener("fetch", (event) => {
const requestUrl = new URL(event.request.url);
if (event.request.method !== "GET" || requestUrl.origin !== self.location.origin) return;
if (event.request.mode === "navigate") {
event.respondWith(
caches.match("./index.html").then((cachedResponse) => cachedResponse || fetch(event.request))
);
return;
}
event.respondWith(
caches.match(event.request).then((cachedResponse) => cachedResponse || fetch(event.request))
);
});