-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsw.js
66 lines (62 loc) · 1.8 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
56
57
58
59
60
61
62
63
64
65
66
/*
* Pixelated
* Copyright (c) Michael Kolesidis <michael.kolesidis@gmail.com>
* GNU Affero General Public License v3.0
*
* ATTENTION! FREE SOFTWARE
* This website is free software (free as in freedom).
* If you use any part of this code, you must make your entire project's source code
* publicly available under the same license. This applies whether you modify the code
* or use it as it is in your own project. This ensures that all modifications and
* derivative works remain free software, so that everyone can benefit.
* If you are not willing to comply with these terms, you must refrain from using any part of this code.
*
* For full license terms and conditions, you can read the AGPL-3.0 here:
* https://www.gnu.org/licenses/agpl-3.0.html
*
*/
const CACHE_NAME = 'pixelated-cache';
const urlsToCache = [
'/',
'/index.html',
'/style.css',
'/pixelated.min.js',
'/texts.js',
'/assets/favicon.ico',
'/assets/apple-touch-icon.png',
'/assets/logo.svg',
'/assets/fonts/inter.woff2',
'/manifest.webmanifest',
];
self.addEventListener('install', (event) => {
event.waitUntil(
caches.open(CACHE_NAME).then((cache) => {
console.log('Opened cache');
return cache.addAll(urlsToCache);
})
);
});
self.addEventListener('fetch', (event) => {
event.respondWith(
caches.match(event.request).then((response) => {
if (response) {
return response;
}
return 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);
}
})
)
)
);
});