forked from rodrigograca31/Samaritan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice-worker.js
38 lines (36 loc) · 1.01 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
//https://mobiforge.com/design-development/taking-web-offline-service-workers
// A list of paths to cache
var paths = [
'/',
'/index.html',
'/manifest.json',
'/phraselist.js',
'/samaritan.js',
'/jquery-1.11.0.min.js',
'/screenfull.min.js',
'/service-worker.js',
'/style.css',
'/font/magdacleanmono-bold.ttf',
'/img/icon.png'
];
self.addEventListener('install', function(event) {
console.log("install");
event.waitUntil(
caches.open('offline-v1')
.then(function(cache) {
return cache.addAll(paths);
})
);
event.waitUntil(self.skipWaiting());
});
self.addEventListener('fetch', function(event) {
console.log("fetch");
// Cache, then network, then fallback for other urls
event.respondWith(
caches.match(event.request).then(function(response) {
return response || fetch(event.request);
}).catch(function() {
//return caches.match('/page/content-not-available-offline');
})
);
});