-
Notifications
You must be signed in to change notification settings - Fork 0
/
sw.js
executable file
·55 lines (52 loc) · 1.64 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
52
53
54
55
const APP_NAME = "AmazonUrlShortener";
const VERSION = "202405290844JST";
const CACHE_NAME = APP_NAME + "_" + VERSION;
const assets = [
"/amazon-url-shortener/",
"/amazon-url-shortener/index.html",
"/amazon-url-shortener/img/favicon.png",
"https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css",
"https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js",
"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css",
"/amazon-url-shortener/css/style.css",
"/amazon-url-shortener/js/main.js",
"/amazon-url-shortener/js/multilingualization.js",
"/amazon-url-shortener/js/indolence.js",
];
/**
* Handling service worker install events
*/
self.addEventListener("install", (e) => {
e.waitUntil(
caches.open(CACHE_NAME).then((cache) => {
return cache.addAll(assets);
})
);
});
/**
* What happens when you access the server from a service worker
*/
self.addEventListener("fetch", (e) => {
e.respondWith(
caches.match(e.request).then((response) => {
// If the file is cached, it will be referenced locally without any communication.
return response ? response : fetch(e.request);
})
);
});
/**
* What happens when a service worker starts
*/
self.addEventListener("activate", (e) => {
e.waitUntil(
caches.keys().then((keyList) => {
return Promise.all(
keyList.map((key) => {
if (key !== CACHE_NAME) {
return caches.delete(key);
}
})
);
})
);
});