chore: use mjs for sw

This commit is contained in:
Ayo Ayco 2024-08-17 21:35:36 +02:00
parent f79e918606
commit 744067d211
2 changed files with 3 additions and 5 deletions

View file

@ -17,7 +17,7 @@ export default defineConfig({
mdx(),
sitemap(),
serviceWorker({
path: "./src/sw.ts",
path: "./src/sw.mjs",
assetCachePrefix: 'cozy-reader',
assetCacheVersionID: VERSION,
logAssets: true,

View file

@ -4,7 +4,7 @@ import { logInfo } from './utils/logger'
* -- find usage in `astro.config.mjs` integrations
* @see https://ayco.io/n/@ayco/astro-sw
*/
const cacheName = `${__prefix ?? 'app'}-v${__version ?? '000'}`
const cacheName = `${__prefix ?? 'app'}-v${__version + '-' + Date.now()}`
const forceLogging = false;
const addResourcesToCache = async (resources) => {
@ -113,9 +113,7 @@ self.addEventListener('activate', (event) => {
self.addEventListener('install', (event) => {
logInfo('installing service worker...', { force: forceLogging, context: 'cozy-sw' })
event.waitUntil(
addResourcesToCache([
...(__assets ?? [])
])
addResourcesToCache(__assets ?? [])
);
self.skipWaiting(); // activate updated SW
});