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); }); }) ); });