-
Notifications
You must be signed in to change notification settings - Fork 0
/
calctvasw.js
82 lines (76 loc) · 2.6 KB
/
calctvasw.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*********************************************************************
*
* CalcTVA Service Worker
*
* Created by Derek Erb Solutions ( https://derekerb.solutions)
* JavaScript programming and CSS styling by
* Victor Polouchine ([email protected])
*
********************************************************************/
// Local all app file assets to be loaded to the precache
const cacheName = 'calctva-cache-v1.0.28b ';
/*************************************************************************
** EVENT LISTENER
** INSTALL
*************************************************************************/
self.addEventListener('install', (event) => {
event.waitUntil(
caches.open(cacheName).then((cache) => {
return cache.addAll([
'/',
'/index.html',
'/css/calctva.css',
'/css/normalise.css',
'/fonts/roboto-regular.ttf',
'/imgs/calc-empty-black.svg',
'/imgs/calc-full-black.svg',
'/imgs/moon.svg',
'/imgs/question-empty-black.svg',
'/imgs/question-full-black.svg',
'/imgs/reset.svg',
'/imgs/settings.svg',
'/imgs/undo.svg',
'/js/calctvaclass.js',
'/js/calctva.js',
'/favicon-512x512.png',
'/favicon-144x144.png',
'/favicon-32x32.png'
]);
})
);
});
/*************************************************************************
** EVENT LISTENER
** ACTIVATE
*************************************************************************/
self.addEventListener('activate', event => {
const cacheAllowlist = [cacheName];
// Remove outdated caches
event.waitUntil(
caches.keys().then(cacheNames => {
return Promise.all(
cacheNames.map(cacheNameEntry => {
if (cacheAllowlist.indexOf(cacheNameEntry) === -1) {
return caches.delete(cacheNameEntry);
}
})
);
})
);
});
/*************************************************************************
** EVENT LISTENER
** FETCH
*************************************************************************/
self.addEventListener('fetch', event => {
event.respondWith(
caches.match(event.request)
.then(response => {
if (response) {
return response;
}
return fetch(event.request)
}).catch(error => {
})
);
});