-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice-worker.js
57 lines (51 loc) · 1.47 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
self.addEventListener('fetch', function(event) {
//console.log('used to intercept requests so we can check for the file or data in the cache');
event.respondWith(
fetch(event.request)
.catch(() => {
return caches.open(CACHE_NAME)
.then((cache) => {
return cache.match(event.request)
})
})
)
});
self.addEventListener('activate', function(event) {
event.waitUntil(
caches.keys()
.then((keyList) => {
return Promise.all(keyList.map((key) => {
if (key !== CACHE_NAME) {
console.log('[ServiceWorker] Removing old cache', key)
return caches.delete(key)
}
}))
})
.then(() => self.clients.claim())
)
});
const CACHE_NAME = 'sw-cache-example';
const toCache = [
'/',
'/static/js/status.js',
'/static/js/pwa.js',
'/static/images/favicon.png',
'/static/js/pwa.webmanifest',
'/static/images/splash-screen.png',
'/static/css/all.min.css',
'/static/css/portal.css',
'/static/js/jquery-3.6.0.min.js',
//webfonts
'/static/webfonts/fa-solid-900.woff',
'/static/webfonts/fa-solid-900.woff2',
'/static/webfonts/fa-solid-900.ttf',
];
self.addEventListener('install', function(event) {
event.waitUntil(
caches.open(CACHE_NAME)
.then(function(cache) {
return cache.addAll(toCache)
})
.then(self.skipWaiting())
)
})