-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice-worker.js
55 lines (53 loc) · 1.49 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
// Listen for install event, set callback
self.addEventListener('install', function(event) {
// Perform some task
event.waitUntil(
caches.open('pdinstall-static-v4').then(function(cache) {
return cache.addAll([
'/lib/images/icon-192.png',
'/lib/images/icon-512.png',
'/lib/style/calendar.css',
'/lib/style/main.css',
'/lib/scripts/swiped-events.js'
// '/index.html',
// '/'
]);
})
);
});
self.addEventListener('activate', function(event) {
event.waitUntil(
caches.keys().then(function(cacheNames) {
return Promise.all(
cacheNames.filter(function(cacheName) {
// Return true if you want to remove this cache,
// but remember that caches are shared across
// the whole origin
// return true;
})
.map(function(cacheName) {
return caches.delete(cacheName);
})
);
})
);
});
self.addEventListener('fetch', function(event) {
event.respondWith(
caches.open('pdinstall-dynamic').then(function(cache) {
return cache.match(event.request).then(function (response) {
return fetch(event.request)
.then(function(response) {
if (event.request.method == 'POST') {
return response;
}
cache.put(event.request, response.clone());
return response;
})
.catch(() => {
return response;
});
});
})
);
});