-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserviceworker.js
More file actions
62 lines (61 loc) · 1.91 KB
/
serviceworker.js
File metadata and controls
62 lines (61 loc) · 1.91 KB
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
56
57
58
59
60
61
62
const assets = [
"/",
"sw-register.js",
"serviceworker.js",
"/Note.html",
"/about.html",
"/Suggest.html",
"css/style.css",
"css/styleabout.css",
"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css",
"https://fonts.googleapis.com/css2?family=Roboto:wght@300&display=swap",
"https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css",
"https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js",
"https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/js/bootstrap.min.js",
"https://fonts.googleapis.com/css2?family=Baloo+Bhai+2&display=swap",
"css/stylenote.css",
"css/stylesuggest.css",
"javascript/index.js",
"javascript/Note.js",
"attachments/slid.jpg",
"attachments/1.jpg",
"attachments/aa.jpg",
"attachments/ap.jpg",
"attachments/ba.jpg",
"attachments/gg.jpg",
"attachments/ff.jpg",
"attachments/cool.jpg",
"attachments/download.jpg",
"attachments/oo.jpg",
"attachments/p.jpg",
"attachments/pa.jpg",
"attachments/pp.jpg",
"attachments/q.jpg",
"attachments/j.jpg",
"attachments/kk.jpg",
"attachments/l.jpeg",
"attachments/ll.jpg",
"attachments/n.jpg",
"attachments/No.jpg",
];
self.addEventListener("install", (event) => {
caches.open("assets").then((cache) => {
cache.addAll(assets);
});
});
self.addEventListener("fetch", (event) => {
event.respondWith(
caches.match(event.request).then((cachedResponse) => {
// Even if the response is in the cache, we fetch it
// and update the cache for future usage
const fetchPromise = fetch(event.request).then((networkResponse) => {
caches.open("assets").then((cache) => {
cache.put(event.request, networkResponse.clone());
return networkResponse;
});
});
// We use the currently cached version if it's there
return cachedResponse || fetchPromise; // cached or a network fetch
})
);
});