This repository was archived by the owner on Sep 9, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsw.js
More file actions
54 lines (49 loc) · 1.25 KB
/
sw.js
File metadata and controls
54 lines (49 loc) · 1.25 KB
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
48
49
50
51
52
53
54
const cacheName = 'devfestlille-19';
const filesToCache = [
'/',
'/js/load.js',
'/css/vars.css',
'/css/barlowsemicondensed-bold-webfont.woff',
'/css/barlowsemicondensed-italic-webfont.woff',
'/css/barlowsemicondensed-regular-webfont.woff',
'/css/boogaloo-regular-webfont.woff',
'/css/boogaloo-regular-webfont.woff2',
'/img/logo.svg',
'/img/logo-big.svg',
'/img/vase.svg',
'/img/hifi.svg',
'/img/tablet.svg'
];
self.addEventListener('install', function(e) {
e.waitUntil(
caches.open(cacheName).then(function(cache) {
return cache.addAll(filesToCache);
})
);
});
self.addEventListener('activate', function(e) {
e.waitUntil(
caches.keys().then(function(keyList) {
return Promise.all(keyList.map(function(key) {
if (key !== cacheName) {
return caches.delete(key);
}
}));
})
);
});
self.addEventListener('fetch', function(e) {
e.respondWith(async function() {
const cachedUrl = await fetch(e.request)
.then(response => {
return caches.open(cacheName).then(function(cache) {
cache.put(e.request, response.clone());
return response;
});
})
.catch(function() {
return caches.match(e.request);
})
return cachedUrl;
}());
});