-
Notifications
You must be signed in to change notification settings - Fork 39
/
sw.js
54 lines (49 loc) · 1.34 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
54
let CACHE_NAME = 'my-site-cache-v1';
let urlsToCache = [
'/',
'index.html',
'imgs/slideshow/Img2.jpg',
'imgs/slideshow/Img4.jpg',
'imgs/slideshow/Img6.jpg',
'imgs/apps/[removal.ai]_tmp-60d72cc48e6d1_EUZTXT.png',
'imgs/apps/brand-icon.png',
'imgs/apps/edge.svg',
'imgs/apps/chrome.svg',
'css/main.css',
'js/main.js',
'js/drag-and-drop.js'
];
self.addEventListener('install', (event) => {
event.waitUntil(
caches.open(CACHE_NAME)
.then(function (cache) {
return cache.addAll(urlsToCache);
})
);
});
self.addEventListener('fetch', (event) => {
event.respondWith(
caches.match(event.request)
.then(function (response) {
// Cache hit - return response
if (response) {
return response;
}
return fetch(event.request);
})
);
});
self.addEventListener('activate', function (event) {
let cacheAllowlist = ['my-site-cache-v1'];
event.waitUntil(
caches.keys().then(function (cacheNames) {
return Promise.all(
cacheNames.map(function (cacheName) {
if (cacheAllowlist.indexOf(cacheName) === -1) {
return caches.delete(cacheName);
}
})
);
})
);
});