forked from mrepol742/mrepol742.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sw.js
22 lines (20 loc) · 825 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
const cacheName = 'mrepol742v3.1';
self.addEventListener('install', (event) => {
event.waitUntil(caches.open(cacheName));
});
self.addEventListener('fetch', async (event) => {
if ((event.request.destination === 'image' || event.request.url.includes("/assets/")) && event.request.url.includes(atob("aHR0cHM6Ly9tcmVwb2w3NDIuZ2l0aHViLmlv"))) {
console.log("destination " + event.request.destination);
console.log("url " + event.request.url);
event.respondWith(caches.open(cacheName).then((cache) => {
return cache.match(event.request).then((cachedResponse) => {
return cachedResponse || fetch(event.request.url).then((fetchedResponse) => {
cache.put(event.request, fetchedResponse.clone());
return fetchedResponse;
});
});
}));
} else {
return;
}
});