Skip to content

Commit 1b53c89

Browse files
committed
fix(service-worker): Update asset paths and improve caching error handling
1 parent 388ddc3 commit 1b53c89

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

src/scripts/service-worker.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ const PRECACHE_ASSETS = [
3434
'/audio/sfx/tridecco.wav',
3535
'/audio/sfx/victory.wav',
3636

37-
'/css/styles.css',
37+
'/styles/styles.css',
3838

39-
'/font/tridecco.ttf',
39+
'/fonts/tridecco.ttf',
4040

4141
'/img/default-avatar.svg',
4242
'/img/backgrounds/broken-glass.jpg',
@@ -93,10 +93,18 @@ const PRECACHE_ASSETS = [
9393

9494
self.addEventListener('install', (event) => {
9595
event.waitUntil(
96-
caches
97-
.open(STATIC_CACHE)
98-
.then((cache) => cache.addAll(PRECACHE_ASSETS))
99-
.then(() => self.skipWaiting()),
96+
(async () => {
97+
const cache = await caches.open(STATIC_CACHE);
98+
99+
for (const asset of PRECACHE_ASSETS) {
100+
try {
101+
const response = await fetch(asset);
102+
await cache.put(asset, response);
103+
} catch (err) {
104+
console.warn(`Failed to cache ${asset}:`, err);
105+
}
106+
}
107+
})().then(() => self.skipWaiting()),
100108
);
101109
});
102110

0 commit comments

Comments
 (0)