-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsw.js
47 lines (42 loc) · 1.37 KB
/
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const CACHE_NAME = 'anext-app-v1.0';
// Use the install event to pre-cache all initial resources.
self.addEventListener('install', event => {
event.waitUntil((async () => {
const cache = await caches.open(CACHE_NAME);
await cache.addAll([
'index.html',
'pages/schedule.html',
'sched.js',
'schedule.json',
'artists.json',
'dealers.json',
'pages/artistsalley.html',
'pages/dealersroom.html',
'pages/hours.html',
'pages/location.html',
'pages/shuttles.html',
'pages/maps.html',
'pages/bagpolicy.html',
'pages/conduct.html',
'pages/cosplaypropspolicy.html',
'pages/dresscode.html',
'pages/about.html'
]);
self.skipWaiting();
})());
});
self.addEventListener('fetch', event => {
event.respondWith((async () => {
const cache = await caches.open(CACHE_NAME);
try {
//We're out of dev time so getting the schedule is online first w/ fallback to cache because updating it is tricky
const fetchResponse = await fetch(event.request);
cache.put(event.request, fetchResponse.clone()).catch( err => console.log(err));
return fetchResponse;
} catch (e) {
// The network failed.
const cachedResponse = await cache.match(event.request);
return cachedResponse;
}
})());
});