-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsw.js
30 lines (29 loc) · 912 Bytes
/
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
// This polyfill provides Cache.add(), Cache.addAll(), and CacheStorage.match()
importScripts('sw-cache-polyfill.js');
//my SW
this.addEventListener('install', function(event){
event.waitUntil(
caches.open('v1').then(function(cache){
return cache.addAll([
'/ngitung/',
'/ngitung/index.html',
'/ngitung/style.css',
'/ngitung/app.js'
]);
})
);
})
this.addEventListener('fetch', function(event) {
var response;
event.respondWith(caches.match(event.request).catch(function() {
return fetch(event.request);
}).then(function(r) {
response = r;
caches.open('v1').then(function(cache) {
cache.put(event.request, response);
});
return response.clone();
}).catch(function() {
return caches.match('/ngitung/index.html');
}));
});