-
Notifications
You must be signed in to change notification settings - Fork 0
/
sw.js
32 lines (28 loc) · 772 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
32
var CACHE_NAME = 'audiobook-player';
//HINT: Make sure that this correctly points to the static resources used for the player
var urlsToCache = [
'index.html',
'polyfills/fetch.js',
'polyfills/urlsearchparams.js',
'player.js'
];
self.addEventListener('install', event => {
event.waitUntil(
caches.open(CACHE_NAME)
.then(function(cache) {
return cache.addAll(urlsToCache);
})
);
self.skipWaiting();
});
self.addEventListener('activate', event => {
clients.claim();
});
/* For audiobooks, files are massive, always do cache first then network. */
self.addEventListener('fetch', event => {
event.respondWith(
caches.match(event.request).then(function(response) {
return response || fetch(event.request);
})
);
});