-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsw.js
30 lines (25 loc) · 883 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
var OFFLINE_CACHE = 'offline';
var offlineFile = 'error.html';
self.addEventListener('install', function(event) {
self.skipWaiting();
var offlinePage = new Request(offlineFile);
event.waitUntil(
fetch(offlinePage).then(function(response) {
return caches.open(OFFLINE_CACHE).then(function(cache) {
return cache.put(offlinePage, response);
});
}));
});
self.addEventListener('fetch', function(event) {
event.respondWith(
fetch(event.request).catch(function(error) {
return caches.open(OFFLINE_CACHE).then(function(cache) {
return cache.match(offlineFile);
});
}));
});
self.addEventListener('refreshOffline', function(response) {
return caches.open(OFFLINE_CACHE).then(function(cache) {
return cache.put(offlinePage, response);
});
});