-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsw.js
38 lines (33 loc) · 1.04 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
// Service worker
// Hopefully this does what it's supposed to and doesn't break
const levelVersion = "252f43d752deaa6417b65ac32c7823f16f0f6ab2";
const levelsBaseURL = `https://raw.githubusercontent.com/Flowit-Game/Levels/${levelVersion}`;
const name = `flowit-web-${levelVersion}`;
const pathsToCache = [
"index.html",
"main.js",
"style.css",
"texture.png",
levelsBaseURL + "levelsEasy.xml",
levelsBaseURL + "levelsMedium.xml",
levelsBaseURL + "levelsHard.xml",
levelsBaseURL + "levelsCommunity.xml",
];
self.addEventListener("install", e => {
e.waitUntil(caches.keys().then(async keys => {
for (let k of keys) {
if (k !== name) {
await caches.delete(k);
}
}
}));
e.waitUntil((async () => {
const cache = await caches.open(name);
await cache.addAll(pathsToCache);
})());
});
self.addEventListener("fetch", event => {
e.respondWith(caches.match(e.request).then(response => {
return response || fetch(e.request);
}));
});