-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsw.js
25 lines (22 loc) · 808 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
// src: https://deanhume.com/create-a-really-really-simple-offline-page-using-service-workers/
var version = '1';
self.addEventListener('install', event => {
event.waitUntil(
caches.open('offline' + version).then(cache =>
cache.addAll([
'frakoblet.html',
'/assets/css/main.css',
'/assets/favicons/apple-touch-icon.png',
'/assets/favicons/favicon-32x32.png',
'/assets/favicons/favicon-16x16.png'
])
)
);
});
self.addEventListener('fetch', event => {
if (event.request.mode === 'navigate')
event.respondWith(fetch(event.request.url).catch(e => caches.match('frakoblet.html')));
else
// Respond with everything else if we can
event.respondWith(caches.match(event.request).then(response => response || fetch(event.request)));
});