-
Notifications
You must be signed in to change notification settings - Fork 14
/
sw.js
59 lines (54 loc) · 1.51 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
52
53
54
55
56
57
58
var cacheName = 'EX-WebThrottle27';
var filesToCache = [
'images/favicon.ico',
'images/carbon_fibre.png',
'images/cover.png',
'images/darkmkBigBackground.png',
'images/darkmkBigFront.png',
'images/lightBigBackground.png',
'images/[email protected]',
'images/lightBigFront.png',
'images/[email protected]',
'images/pattern.png',
'css/jquery.rotaryswitch.css',
'css/pwa.css',
'css/roundslider.min.css',
'css/fonts/icomoon.eot',
'css/fonts/icomoon.svg',
'css/fonts/icomoon.ttf',
'css/fonts/icomoon.woff',
];
self.addEventListener('install', function(e) {
console.log('[ServiceWorker] Installing');
e.waitUntil(
caches.open(cacheName).then(function(cache) {
console.log('[ServiceWorker] Caching app shell');
return cache.addAll(filesToCache);
})
);
console.log('[ServiceWorker] Install Complete');
});
// self.addEventListener('activate', event => {
// event.waitUntil(self.clients.claim());
// });
self.addEventListener('activate', event => {
// Remove old caches
event.waitUntil(
(async () => {
const keys = await caches.keys();
return keys.map(async (cache) => {
if(cache !== cacheName) {
console.log('Service Worker: Removing old cache: '+cache);
return await caches.delete(cache);
}
})
})()
)
})
self.addEventListener('fetch', event => {
event.respondWith(
caches.match(event.request, {ignoreSearch:true}).then(response => {
return response || fetch(event.request);
})
);
});