-
Notifications
You must be signed in to change notification settings - Fork 1
/
sw.js
33 lines (29 loc) · 673 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
33
/* eslint no-console: 0 */
const CACHE_NAME = 'v2:cache';
let toCache = [
'./',
'./css/material.min.css',
'./css/main.css',
'./js/material.min.js',
'./js/script.js',
'./images/battery.png',
'./manifest.json',
'https://fonts.googleapis.com/icon?family=Material+Icons'
];
self.addEventListener('install', event => {
event.waitUntil(
caches
.open(CACHE_NAME)
.then(cache => {
console.log('Opened cache');
return cache.addAll(toCache);
})
);
});
self.addEventListener('fetch', event => {
event.respondWith(
caches
.match(event.request)
.then(response => response || fetch(event.request))
);
});