chore: use mjs for sw

This commit is contained in:
Ayo Ayco 2024-08-17 21:23:23 +02:00
parent ba274641ff
commit bcc1574e8f
2 changed files with 4 additions and 4 deletions

View file

@ -8,7 +8,7 @@ export default defineConfig({
integrations: [ integrations: [
sitemap(), sitemap(),
serviceWorker({ serviceWorker({
path: './src/sw.ts', path: './src/sw.mjs',
assetCachePrefix: 'ayco-personal-site', assetCachePrefix: 'ayco-personal-site',
excludeRoutes: [ excludeRoutes: [
'/threads' '/threads'

View file

@ -5,13 +5,13 @@
*/ */
const cacheName = `${__prefix ?? 'app'}-v${__version ?? '000'}` const cacheName = `${__prefix ?? 'app'}-v${__version ?? '000'}`
const addResourcesToCache = async (resources: string[]) => { const addResourcesToCache = async (resources) => {
const cache = await caches.open(cacheName); const cache = await caches.open(cacheName);
console.log('[personal-sw]: adding resources to cache...', resources) console.log('[personal-sw]: adding resources to cache...', resources)
await cache.addAll(new Set([...resources])); await cache.addAll(new Set([...resources]));
}; };
const putInCache = async (request: Request, response: Response) => { const putInCache = async (request, response) => {
const cache = await caches.open(cacheName); const cache = await caches.open(cacheName);
console.log('[personal-sw]: adding one response to cache...', request.url) console.log('[personal-sw]: adding one response to cache...', request.url)
// if exists, replace // if exists, replace
@ -25,7 +25,7 @@ const putInCache = async (request: Request, response: Response) => {
}; };
const cacheAndRevalidate = async ({ request, preloadResponsePromise, fallbackUrl }: {request: Request, preloadResponsePromise: Promise<any>, fallbackUrl: string}) => { const cacheAndRevalidate = async ({ request, preloadResponsePromise, fallbackUrl }) => {
const cache = await caches.open(cacheName); const cache = await caches.open(cacheName);