-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
service-worker.js
34 lines (31 loc) · 908 Bytes
/
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
'use strict';
const cacheName = 'v0.23';
const offlineUrl = '/offline.html';
self.addEventListener('install', e => {
// once the SW is installed, go ahead and fetch the resources
// to make this work offline
e.waitUntil(
caches.open(cacheName).then(cache => {
return cache.addAll([
'/index.html',
'/manifest.json',
'/css/idiots.css',
'/js/min/idiots.min.js',
'/js/libraries/jquery.min.js',
'/svg/offline.svg',
offlineUrl
]).then(() => self.skipWaiting());
})
);
});
self.addEventListener('fetch', function(event) {
if (event.request.mode === 'navigate' || (event.request.method === 'GET' && event.request.headers.get('accept').includes('text/html'))) {
event.respondWith(
fetch(event.request.url).catch(error => {
return caches.match(offlineUrl);
})
);
} else {
return response
}
});