-
Notifications
You must be signed in to change notification settings - Fork 5
/
service-worker.js
48 lines (36 loc) · 1.21 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
// This service worker will never refetch assets once it's installed the first time. This means that in order for the app to update, the service worker must change and recache the assets. Changing this verions number will do that.
const version = "0.25"
const static_cache_name = 'static_assets-' + version;
self.addEventListener('install', e => e.waitUntil((async () => {
const static_assets = await caches.open(static_cache_name);
await static_assets.addAll([
// Main page
'/',
'/?utm_source=homescreen',
'index.html',
'app.webmanifest',
// Favicons
'icons/logo-opt.svg',
'icons/logo-180.png',
'style/index.css',
'style/Poppins/Poppins-Regular.ttf',
'js/elements.mjs',
'js/encode_wav.mjs',
'js/index.mjs',
'js/install.mjs',
'js/lib.mjs',
'js/morse-table.mjs',
]);
await self.skipWaiting();
})()));
self.addEventListener('activate', e => e.waitUntil((async () => {
await clients.claim(); // Claim all the active pages.
const keys = await caches.keys();
keys.splice(keys.indexOf(static_cache_name));
await Promise.all(keys.map(k => caches.delete(k)));
})()));
self.addEventListener('fetch', e => {
e.respondWith(
caches.match(e.request).then(res => res || fetch(e.request))
);
});