-
Notifications
You must be signed in to change notification settings - Fork 0
/
service_worker.js
49 lines (44 loc) · 1.35 KB
/
service_worker.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
42
43
44
45
46
47
48
49
const cacheName = "JummBox";
self.addEventListener("install", function(event) {
event.waitUntil(
caches.open(cacheName).then(function(cache) {
return cache.addAll([
"/",
"/beepbox_editor.min.js",
"/player/",
"/player/beepbox_player.min.js",
"/2_4/",
"/2_4/beepbox_editor.min.js",
"/2_4/player/",
"/2_4/player/beepbox_player.min.js",
//"/2_3/",
//"/2_3/beepbox_editor.min.js",
"https://cdn.jsdelivr.net/npm/[email protected]/lame.min.js",
]).then(() => self.skipWaiting());
})
);
});
self.addEventListener("activate", function(event) {
event.waitUntil(self.clients.claim());
});
self.addEventListener("fetch", function(event) {
if (event.request.method != "GET") return;
event.respondWith(
caches.open(cacheName).then(function(cache) {
return fetch(event.request).then(function(response) {
// If this is a local resource or related to google fonts, add
// it to the permanent cache.
if (event.request.url.startsWith(self.location.origin) ||
event.request.url.startsWith("https://fonts.googleapis.com") ||
event.request.url.startsWith("https://fonts.gstatic.com") ||
event.request.url.startsWith("https://cdn.jsdelivr.net"))
{
cache.put(event.request, response.clone());
}
return response;
}).catch(function() {
return cache.match(event.request);
});
})
);
});