-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsw.js
31 lines (29 loc) · 984 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
31
self.addEventListener('install', event => {
console.log('Installing offline content caching V2');
self.skipWaiting();
});
self.addEventListener('activate', function(event) {
console.log('Activating offline content caching V2');
event.waitUntil(
caches.keys().then(function(cacheNames) {
return Promise.all(
cacheNames.map(function(cacheName) {
console.log('Wiping cache: ' + cacheName)
return caches.delete(cacheName);
})
);
})
);
});
self.addEventListener('fetch', function(event) {
event.respondWith(
caches.open('offline-content').then(function(cache) {
return fetch(event.request).then(function(response) {
cache.put(event.request, response.clone());
return response;
}).catch(function() {
return caches.match(event.request);
})
})
);
});