-
Notifications
You must be signed in to change notification settings - Fork 0
/
serviceworker.js
51 lines (49 loc) · 1.42 KB
/
serviceworker.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
var staticCacheName = "pwa-v" + new Date().getTime();
var filesToCache = [
'public/img/icons/otadjer-72x72.png',
'public/img/icons/otadjer-96x96.png',
'public/img/icons/otadjer-128x128.png',
'public/img/icons/otadjer-144x144.png',
'public/img/icons/otadjer-152x152.png',
'public/img/icons/otadjer-192x192.png',
'public/img/icons/otadjer-384x384.png',
'public/img/icons/otadjer-512x512.png'
];
/*
// Cache on install
self.addEventListener("install", event => {
this.skipWaiting();
event.waitUntil(
caches.open(staticCacheName)
.then(cache => {
return cache.addAll(filesToCache);
})
)
});
*/
/*
// Clear cache on activate
self.addEventListener('activate', event => {
event.waitUntil(
caches.keys().then(cacheNames => {
return Promise.all(
cacheNames
.filter(cacheName => (cacheName.startsWith("pwa-")))
.filter(cacheName => (cacheName !== staticCacheName))
.map(cacheName => caches.delete(cacheName))
);
})
);
});*/
// Serve from Cache
self.addEventListener("fetch", event => {
event.respondWith(
caches.match(event.request)
.then(response => {
return response || fetch(event.request);
})
.catch(() => {
return caches.match('offline');
})
)
});