-
Notifications
You must be signed in to change notification settings - Fork 0
/
sw.js
executable file
·51 lines (48 loc) · 1.38 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
40
41
42
43
44
45
46
47
48
49
50
51
const version = "1.02.01";
const cacheName = "shasha-" + version;
const assets = [
"/assets/css/animate.min.css",
"/assets/img/logo.png",
"/assets/img/logo-maskable.png",
"/assets/img/screenshot-1-710x1300.png",
"/assets/img/screenshot-2-710x1300.png",
"/assets/img/screenshot-3-710x1300.png",
"/assets/js/app.js",
"/assets/js/linkify-jquery.min.js",
"/assets/js/linkify.min.js",
"/assets/js/main.js",
];
// install event
self.addEventListener("install", evt => {
evt.waitUntil(
caches.open(cacheName).then((cache) => {
console.log("Enregistrement des assets dans le cache");
cache.addAll(assets);
})
);
});
// activate event
self.addEventListener("activate", evt => {
evt.waitUntil(
caches.keys().then(keys => {
return Promise.all(keys
.filter(key => key !== cacheName)
.map(key => caches.delete(key))
);
})
);
});
self.addEventListener("fetch", evt => {
const url = new URL(evt.request.url);
console.log(url.origin, location.origin)
if (url.origin == location.origin) {
switch (url.pathname) {
case "/version":
evt.respondWith(new Response(version));
break;
}
} else {
console.log("Retour par défaut");
evt.respondWith(fetch(evt.request));
}
});