|
1 | 1 | const CACHE_NAME = "codehubx-cache-v1";
|
2 |
| -const urlsToCache = [ |
3 |
| - "/", |
4 |
| - "/index.html", |
5 |
| - "/styles/style.css", |
6 |
| - "/scripts/main.js", |
7 |
| - "https://cdn.jsdelivr.net/npm/[email protected]/dist/showdown.min.js", |
8 |
| - "/data/README.md", |
9 |
| - "/data/summary.md", |
10 |
| - "/data/ai.md", |
11 |
| - "/data/entertainment.md", |
12 |
| - "/data/piracy.md", |
13 |
| - "/data/free-resources.md", |
14 |
| - "/data/github-repos.md", |
15 |
| - "/data/tools.md", |
16 |
| - "/data/fake-identity.md", |
17 |
| -]; |
| 2 | +const urlsToCache = ["/", "/index.html", "/styles/style.css", "/scripts/main.js", "https://cdn.jsdelivr.net/npm/[email protected]/dist/showdown.min.js", "/data/README.md", "/data/summary.md", "/data/ai.md", "/data/entertainment.md", "/data/piracy.md", "/data/free-resources.md", "/data/github-repos.md", "/data/tools.md", "/data/fake-identity.md", "https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined", "https://fonts.googleapis.com/css2?family=Titillium+Web:wght@600&display=swap", "https://fonts.googleapis.com/css2?family=Space+Grotesk:[email protected]&display=swap", "https://fonts.googleapis.com/css2?family=Nabla&display=swap"]; |
18 | 3 |
|
19 | 4 | self.addEventListener("install", (event) => {
|
20 | 5 | event.waitUntil(
|
21 |
| - caches.open(CACHE_NAME).then((cache) => {` ` |
| 6 | + caches.open(CACHE_NAME).then((cache) => { |
22 | 7 | return cache.addAll(urlsToCache);
|
23 | 8 | })
|
24 | 9 | );
|
25 | 10 | });
|
26 | 11 |
|
27 | 12 | self.addEventListener("fetch", (event) => {
|
28 | 13 | event.respondWith(
|
29 |
| - caches.match(event.request).then((response) => { |
30 |
| - return response || fetch(event.request); |
31 |
| - }) |
| 14 | + caches |
| 15 | + .match(event.request) |
| 16 | + .then((response) => { |
| 17 | + return ( |
| 18 | + response || |
| 19 | + fetch(event.request).then((response) => { |
| 20 | + return caches.open(CACHE_NAME).then((cache) => { |
| 21 | + cache.put(event.request, response.clone()); |
| 22 | + return response; |
| 23 | + }); |
| 24 | + }) |
| 25 | + ); |
| 26 | + }) |
| 27 | + .catch(() => { |
| 28 | + return caches.match("/index.html"); |
| 29 | + }) |
32 | 30 | );
|
33 | 31 | });
|
34 | 32 |
|
|
0 commit comments