-
Notifications
You must be signed in to change notification settings - Fork 0
/
service-worker.js
58 lines (53 loc) · 1.56 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
50
51
52
53
54
55
56
57
58
const cacheName = 'Tesomas.Camp v2.0.30';
const precacheResources = [
/*'/index',
'/areas',
'/info',
'/social',
'/store',*/
'/css/main.css',
'/css/waltographUI.ttf',
'/images/background-dark.png',
'/images/background-light.png',
'/images/favicon.ico',
/*'/resources/2022_TSC_Guidebook.pdf',*/
'https://kit.fontawesome.com/1b88120e53.js',
'https://ka-f.fontawesome.com/releases/v5.15.3/css/free.min.css?token=1b88120e53',
'https://ka-f.fontawesome.com/releases/v5.15.3/css/free-v4-shims.min.css?token=1b88120e53',
];
self.addEventListener('install', event => {
event.waitUntil(
caches.open(cacheName)
.then(cache => {
return cache.addAll(precacheResources);
})
.then(() => {
return self.skipWaiting();
})
);
});
self.addEventListener('fetch', event => {
event.respondWith(caches.match(event.request)
.then(cachedResponse => {
if (cachedResponse) {
return cachedResponse;
}
return fetch(event.request);
})
);
});
self.addEventListener('activate', event => {
console.log('Activating new service worker...');
const cacheWhitelist = [cacheName];
event.waitUntil(
caches.keys().then(cacheNames => {
return Promise.all(
cacheNames.map(cacheName => {
if (cacheWhitelist.indexOf(cacheName) === -1) {
return caches.delete(cacheName);
}
})
);
})
);
});