-
Notifications
You must be signed in to change notification settings - Fork 0
/
sw.js
53 lines (46 loc) · 1.21 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
48
49
50
51
52
53
const CACHE = 'themattfiles';
var app = [
'404.html',
'assets/icons/icon-128x128.png',
'assets/icons/icon-144x144.png',
'assets/icons/icon-152x152.png',
'assets/icons/icon-192x192.png',
'assets/icons/icon-384x384.png',
'assets/icons/icon-512x512.png',
'assets/icons/icon-72x72.png',
'assets/icons/icon-96x96.png',
'assets/img/penpen.svg',
'main.js',
'favicon.ico',
'index.html',
];
self.addEventListener('install', (event) => {
// console.log('Installed.');
event.waitUntil(
caches.open(CACHE)
.then((cache) => {
// console.log('Cache all.');
return cache.addAll(app);
})
);
});
self.addEventListener('activate', () => {
// console.log('Activated.');
});
self.addEventListener('fetch', (event) => {
event.respondWith(
caches.match(event.request).then((req) => {
// console.log('Fetching: ', event.request.url);
return req ||
fetch(event.request)
.then((res) => {
return caches.open(CACHE)
.then((cache) => {
// console.log('Caching: ', event.request.url);
cache.put(event.request, res.clone());
return res;
});
});
})
);
});