-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathservice-worker.js
More file actions
32 lines (25 loc) · 1.02 KB
/
Copy pathservice-worker.js
File metadata and controls
32 lines (25 loc) · 1.02 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
/**
* Service Worker pour Keskonjoue PWA
* Active le mode offline complet avec lecture musicale
*/
import { precacheAndRoute, cleanupOutdatedCaches, matchPrecache } from "workbox-precaching";
import { registerRoute, NavigationRoute, Route } from "workbox-routing";
// Précache tous les assets du build Vite (HTML, JS, CSS, images, soundfonts)
precacheAndRoute(self.__WB_MANIFEST);
// Gère la navigation SPA avec stratégie Cache First
// Retourne index.html depuis le cache sans attendre le réseau
const navigationHandler = async () => {
const cachedResponse = await matchPrecache('/index.html');
return cachedResponse || fetch('/index.html');
};
const navigationRoute = new NavigationRoute(navigationHandler);
registerRoute(navigationRoute);
// Nettoie les anciens caches lors des mises à jour
cleanupOutdatedCaches();
// Active immédiatement le nouveau service worker
self.addEventListener("install", () => {
self.skipWaiting();
});
self.addEventListener("activate", (event) => {
event.waitUntil(clients.claim());
});