-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsw.js
41 lines (41 loc) · 1.35 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
"use strict";
const swWorker = self;
const APP_NAME = "akari-lrc-maker";
const VERSION = "5.6.6";
const HASH = "26783c9";
const CACHENAME = `${APP_NAME}-${VERSION}-${HASH}`;
swWorker.addEventListener("install", () => {
swWorker.skipWaiting();
});
swWorker.addEventListener("activate", (event) => {
event.waitUntil(caches.keys().then((cacheNames) => {
return Promise.all([
swWorker.clients.claim(),
...cacheNames
.filter((cacheName) => {
return cacheName.startsWith(APP_NAME) && cacheName !== CACHENAME;
})
.map((cacheName) => {
return caches.delete(cacheName);
}),
]);
}));
});
swWorker.addEventListener("fetch", (event) => {
if (event.request.method !== "GET") {
return;
}
const url = new URL(event.request.url);
if (!/(?:\.css|\.js|\.svg)$/i.test(url.pathname) && url.origin !== swWorker.location.origin) {
return;
}
event.respondWith(caches.match(event.request).then((match) => match ||
caches.open(CACHENAME).then((cache) => fetch(event.request).then((response) => {
if (response.status !== 200) {
return response;
}
cache.put(event.request, response.clone());
return response;
}))));
});
//# sourceMappingURL=sw.js.map