mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender-pwa.git
synced 2025-07-16 09:38:51 +02:00
29 lines
799 B
JavaScript
29 lines
799 B
JavaScript
import { precacheAndRoute, cleanupOutdatedCaches } from "workbox-precaching";
|
|
import { clientsClaim } from "workbox-core";
|
|
|
|
self.skipWaiting();
|
|
clientsClaim();
|
|
|
|
cleanupOutdatedCaches();
|
|
|
|
// Precache the files from the manifest
|
|
precacheAndRoute(self.__WB_MANIFEST);
|
|
|
|
// Custom precaching logic for the /api/modules endpoint
|
|
self.addEventListener("install", (event) => {
|
|
event.waitUntil(
|
|
caches.open("api-modules-cache").then((cache) => {
|
|
return fetch("/api/modules")
|
|
.then((response) => {
|
|
if (response.ok) {
|
|
return cache.put("/api/modules", response);
|
|
}
|
|
throw new Error("Failed to fetch /api/modules");
|
|
})
|
|
.catch((error) => {
|
|
console.error("Precaching /api/modules failed:", error);
|
|
});
|
|
}),
|
|
);
|
|
});
|