-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsw.js
51 lines (48 loc) · 1.29 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
39
40
41
42
43
44
45
46
47
48
49
50
51
const CACHE_NAME = 'billooo-v1';
const ASSETS_TO_CACHE = [
'/',
'/index.html',
'/manifest.json',
'/src/css/styles.css',
'/src/js/app.js',
'/src/js/crdt.js',
'/src/js/peer-manager.js',
'/src/js/expense-calculator.js',
'https://unpkg.com/[email protected]/dist/peerjs.min.js',
'/icons/72.png',
'/icons/96.png',
'/icons/128.png',
'/icons/144.png',
'/icons/152.png',
'/icons/192.png',
'/icons/384.png',
'/icons/512.png'
];
self.addEventListener('install', (event) => {
event.waitUntil(
caches.open(CACHE_NAME)
.then((cache) => cache.addAll(ASSETS_TO_CACHE))
);
});
self.addEventListener('fetch', (event) => {
event.respondWith(
caches.match(event.request)
.then((response) => {
// Return cached version or fetch new version
return response || fetch(event.request);
})
);
});
self.addEventListener('activate', (event) => {
event.waitUntil(
caches.keys().then((cacheNames) => {
return Promise.all(
cacheNames.map((cacheName) => {
if (cacheName !== CACHE_NAME) {
return caches.delete(cacheName);
}
})
);
})
);
});