-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsw.js
More file actions
53 lines (46 loc) · 1.24 KB
/
Copy pathsw.js
File metadata and controls
53 lines (46 loc) · 1.24 KB
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
// Must be bumped on every deploy that changes index.html/manifest.json —
// this is the only signal that makes the browser treat sw.js as changed and
// install/activate a fresh worker. If it's left stale, already-installed
// PWAs keep serving whatever was cached under the old name indefinitely
// (this has silently happened before: see the v1.25.6 and v1.28.0 fixes).
const CACHE_NAME = 'nsnvc-tracker-v1.29.11';
const urlsToCache = [
'./',
'./index.html',
'./manifest.json'
];
self.addEventListener('install', event => {
self.skipWaiting();
event.waitUntil(
caches.open(CACHE_NAME)
.then(cache => cache.addAll(urlsToCache))
);
});
self.addEventListener('fetch', event => {
event.respondWith(
caches.match(event.request)
.then(response => {
if (response) {
return response;
}
return fetch(event.request);
})
);
});
self.addEventListener('activate', event => {
event.waitUntil(
Promise.all([
clients.claim(),
caches.keys().then(cacheNames => {
return Promise.all(
cacheNames.map(cacheName => {
if (cacheName !== CACHE_NAME) {
return caches.delete(cacheName);
}
})
);
})
])
);
});