forked from scanapp-org/scanapp-org.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsw.js
53 lines (48 loc) · 1.64 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
/**
* Service worker for scanapp PWA.
*/
// On new version, change this name.
var cacheName = 'v2.6.0.1:static';
self.addEventListener('install', function(event) {
// prevents the waiting, meaning the service worker activates
// as soon as it's finished installing
// NOTE: don't use this if you don't want your sw to control pages
// that were loaded with an older version
self.skipWaiting();
event.waitUntil(
caches.open(cacheName).then(function(cache) {
return cache.addAll([
// As new files are added, update this.
'/assets/app.v2.6.0.css',
// '/assets/js/scanapp-js.pro.min.v2.5.9.js',
'/assets/main.css',
'/assets/css/index.v2.5.1.css',
'/assets/fonts/ibm-plex-sans/ibm-plex-sans-v2-latin-300.woff2',
]);
}).then(function() {
self.skipWaiting();
})
);
});
// Remove old cache if any.
self.addEventListener('activate', (event) => {
event.waitUntil((function(e) {
return caches.keys().then(function(cacheNames) {
return Promise.all(cacheNames.map(function(cacheName) {
if (self.cacheName !== cacheName) {
return caches.delete(cacheName);
}
}))
});
})());
});
// With request network
self.addEventListener('fetch', function(event) {
event.respondWith(
// try the cache
caches.match(event.request).then(function(response) {
// return it if there is a response or else fetch again.
return response || fetch(event.request);
})
);
});