-
Notifications
You must be signed in to change notification settings - Fork 2
/
sw.js
44 lines (41 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
39
40
41
42
43
44
let cacheName = 'sorting-web';
let contentToCache = [
'/',
'/index.html',
'./style.css',
'./scripts/script.js',
'./scripts/bubbleSort.js',
'./scripts/selectionSort.js',
'./scripts/mergeSort.js',
'./scripts/modifiedBubbleSort.js',
'./scripts/quickSort.js',
'./scripts/insertionSort.js',
'./images/surftocat-512x512.png'
]
self.addEventListener('install', (e) => {
console.log('[Service Worker] Install');
e.waitUntil(
caches.open(cacheName).then((cache) => {
console.log('[Service Worker] Caching assets');
cache.addAll(contentToCache);
})
);
});
self.addEventListener('activate', (e) => {
e.waitUntil(
caches.keys().then((keyList) => {
return Promise.all(keyList.map((key) => {
if(key !== cacheName) {
return caches.delete(key);
}
}));
})
);
});
self.addEventListener('fetch', (e) => {
e.respondWith(
caches.match(e.request).then(res=>{
return res || fetch(e.request);
})
);
});