-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsw.js
More file actions
45 lines (43 loc) · 1.62 KB
/
Copy pathsw.js
File metadata and controls
45 lines (43 loc) · 1.62 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
// sw.js
const CACHE_NAME = '4re5-cache-v1';
const urlsToCache = [
'https://cdn.jsdelivr.net/npm/canvas-confetti@1.5.1/dist/confetti.browser.min.js',
'https://raw.githubusercontent.com/4re5group/4re5group.github.io/main/header.html',
'https://raw.githubusercontent.com/4re5group/4re5group.github.io/main/footer.html',
'https://api.github.com/users/4re5group/repos',
'https://api.github.com/repos/4RE5group/4RE5group.github.io/contents/products'
];
self.addEventListener('install', event => {
event.waitUntil(
caches.open(CACHE_NAME)
.then(cache => {
return cache.addAll(urlsToCache);
})
);
});
try {
self.addEventListener('fetch', event => {
event.respondWith(
caches.match(event.request)
.then(response => {
if (response) {
return response;
}
return fetch(event.request)
.then(response => {
if (!response || response.status !== 200 || response.type !== 'basic') {
return response;
}
const responseToCache = response.clone();
caches.open(CACHE_NAME)
.then(cache => {
cache.put(event.request, responseToCache);
});
return response;
});
})
);
});
} catch {
console.warn("Cache service worker failed.");
}