/// /// // Force load service worker types const self = globalThis as unknown as ServiceWorkerGlobalScope const cacheName = 'v1' //TODO dynamique cache key const _preCachedPaths = ['/', '/css/*', '/assets/*'] //TODO pre-cache these paths export function main() { self.addEventListener('install', (event) => { //TODO handle installation event.waitUntil( addToCache([]), ) }) self.addEventListener('activate', () => { //TODO handle activation }) self.addEventListener('fetch', (_event) => { //TODO add fetch strategies }) self.addEventListener('push', (event) => { const { title, options } = (event.data?.json() ?? {}) as { title?: string options?: Partial } if (title) { event.waitUntil( self.registration.showNotification(title, options), ) } }) } async function addToCache(ressources: string[]) { const cache = await caches.open(cacheName) //TODO dynamique cache key await cache.addAll(ressources) //TODO list statics }