-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsw.js
31 lines (29 loc) · 954 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
23
24
25
26
27
28
29
30
31
var cacheName = 'muslum-salah-time-pwa';
var filesToCache = [
'/',
'/index.html',
'/css/bootstrap.rtl.min.css',
'/css/style.css'
];
// Installing Service Worker
self.addEventListener('install', (e) => {
console.log('[Service Worker] Install');
e.waitUntil((async () => {
const cache = await caches.open(cacheName);
console.log('[Service Worker] Caching all: app shell and content');
await cache.addAll(filesToCache);
})());
});
// Fetching content using Service Worker
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;
})());
});