-
Notifications
You must be signed in to change notification settings - Fork 0
/
sw.js
44 lines (38 loc) · 1.05 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
const CACHE = 'battery-life-v1';
const FILES = [
'index.html',
'battery-charging-x48.png',
'battery-charging-x96.png',
'battery-charging-x128.png',
'battery-charging-x144.png',
'battery-charging-x192.png',
'battery-charging-x512.png',
'battery-charging.png',
'battery-charging.svg',
'battery.svg',
'main.js',
'https://cdn.rawgit.com/twbs/bootstrap/master/dist/css/bootstrap.min.css'
];
self.addEventListener('install', evt => {
evt.waitUntil(
caches
.open(CACHE)
.then(cache => cache.addAll(FILES))
);
});
self.addEventListener('fetch', function(evt) {
if (evt.request.url.startsWith('data')) return;
evt.respondWith(
caches
.open(CACHE)
.then(cache => cache
.match(evt.request)
.then(matching => matching || Promise.reject()))
);
evt.waitUntil(
caches
.open(CACHE)
.then(cache => fetch(evt.request)
.then(response => cache.put(evt.request, response)))
);
});