-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice-worker.js
63 lines (60 loc) · 1.59 KB
/
service-worker.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
56
57
58
59
60
61
62
63
const CACHE_NAME = "milesonerd-cache-v1";
const urlsToCache = [
"/",
"/index.html",
"/about",
"/about.html",
"/contact",
"/contact.html",
"/acessibility",
"/acessibility.html",
"/policies-and-terms",
"/policies-and-terms.html",
"/404.html",
"/blog",
"/blog/index.html",
"/blog/posts/12-17-2024 Blog.md",
"/blog/scripts/list-posts.js",
"/style.css",
"/scripts/functions.js",
"/scripts/quotes.js",
"https://milesonerd.github.io/img/android-chrome-192x192.png",
"https://milesonerd.github.io/img/android-chrome-512x512.png",
"https://milesonerd.github.io/img/apple-touch-icon.png",
"https://milesonerd.github.io/img/favicon-16x16.png",
"https://milesonerd.github.io/img/favicon-32x32.png",
"https://milesonerd.github.io/img/favicon.ico",
"https://milesonerd.github.io/img/site.webmanifest",
"https://milesonerd.github.io/image/Phoenix.jpg",
"/feed.xml",
"/robots.txt",
"/sitemap.xml",
];
self.addEventListener("install", event => {
event.waitUntil(
caches.open(CACHE_NAME).then(cache => {
return cache.addAll(urlsToCache);
})
);
});
self.addEventListener("fetch", event => {
event.respondWith(
caches.match(event.request).then(response => {
return response || fetch(event.request);
})
);
});
self.addEventListener("activate", event => {
const cacheWhitelist = [CACHE_NAME];
event.waitUntil(
caches.keys().then(cacheNames =>
Promise.all(
cacheNames.map(cacheName => {
if (!cacheWhitelist.includes(cacheName)) {
return caches.delete(cacheName);
}
})
)
)
);
});