-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsw.js
34 lines (25 loc) · 896 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
32
33
34
self.addEventListener('install', function(event) {
event.waitUntil(self.skipWaiting()); // Activate worker immediately
});
self.addEventListener('activate', function(event) {
event.waitUntil(self.clients.claim()); // Become available to all pages
});
async function liss_answer(e) {
const answer = await fetch(e.request);
return answer.status !== 404
? answer
: new Response("", {
status: 200,
statusText: "Accepted",
headers: new Headers({
"Status" : answer.status,
"StatusText": answer.statusText
})
});
}
self.addEventListener('fetch', (e) => {
const isLissAuto = e.request.headers.has('liss-auto');
if( ! isLissAuto )
return;
return e.respondWith( liss_answer(e) )
});