-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsw.js
40 lines (36 loc) · 1.26 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
const cacheName = 'StopAdware-v1.0.0';
const addResourcesToCache = async (resources) => {
const cache = await caches.open(cacheName);
await cache.addAll(resources);
};
self.addEventListener("install", (event) => {
event.waitUntil(
addResourcesToCache([
"/StopAdwarePWA/",
"/StopAdwarePWA/index.html",
"/StopAdwarePWA/favicon.ico",
"/StopAdwarePWA/assets/js/script.js",
"/StopAdwarePWA/assets/css/style.css",
"/StopAdwarePWA/assets/img/icon-32.png",
"/StopAdwarePWA/assets/img/icon-64.png",
"/StopAdwarePWA/assets/img/icon-128.png",
"/StopAdwarePWA/assets/img/icon-180.png",
"/StopAdwarePWA/assets/img/icon-192.png",
"/StopAdwarePWA/assets/img/icon-196.png",
"/StopAdwarePWA/assets/img/icon-256.png",
"/StopAdwarePWA/assets/img/icon-512.png",
])
);
});
self.addEventListener('fetch', (e) => {
e.respondWith((async () => {
const r = await caches.match(e.request);
console.log(`[Service Worker] Fetching resource: ${e.request.url}`);
if (r) return r;
const response = await fetch(e.request);
const cache = await caches.open(cacheName);
console.log(`[Service Worker] Caching new resource: ${e.request.url}`);
cache.put(e.request, response.clone());
return response;
})());
});