-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsw.js
31 lines (29 loc) · 785 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
const addResourcesToCache = async (resources) => {
const cache = await caches.open("v1");
await cache.addAll(resources);
};
self.addEventListener('install', (event) => {
event.waitUntil(
addResourcesToCache([
'/'
])
);
});
self.addEventListener('fetch', function(event) {
if(event.request.url.startsWith('chrome-extension')){
//skip request
}
else {
event.respondWith(async function() {
try{
var res = await fetch(event.request);
var cache = await caches.open('cache');
cache.put(event.request.url, res.clone());
return res;
}
catch(error){
return caches.match(event.request);
}
}());
}
});