diff --git a/public/sw.js b/public/sw.js index 2793de65..ab6b2070 100644 --- a/public/sw.js +++ b/public/sw.js @@ -1,7 +1,6 @@ import { CacheableResponsePlugin } from 'workbox-cacheable-response'; import { ExpirationPlugin } from 'workbox-expiration'; import * as navigationPreload from 'workbox-navigation-preload'; -import { pageCache } from 'workbox-recipes'; import { RegExpRoute, registerRoute, Route } from 'workbox-routing'; import { CacheFirst, @@ -13,9 +12,8 @@ navigationPreload.enable(); self.__WB_DISABLE_DEV_LOGS = true; -// Cache HTML pages -pageCache({ - warmCache: ['./compose/'], +self.addEventListener('activate', (event) => { + event.waitUntil(caches.delete('pages')); }); // Custom plugin to manage hashed assets diff --git a/vite.config.js b/vite.config.js index bf57e025..d0252a0e 100644 --- a/vite.config.js +++ b/vite.config.js @@ -282,12 +282,49 @@ export default defineConfig({ const cssFiles = Object.keys(bundle).filter((file) => file.endsWith('.css'), ); + const lines = [ + '/*', + ' Cache-Control: no-store', + ]; if (cssFiles.length > 0) { - const links = cssFiles - .map((file) => ` Link: <${file}>; rel=preload; as=style`) - .join('\n'); - fs.writeFileSync(resolve(__dirname, 'dist/_headers'), `/\n${links}`); + lines.push( + '/', + ...cssFiles.map( + (file) => ` Link: <${file}>; rel=preload; as=style`, + ), + ); } + [ + '/apple-touch-icon.png', + '/favicon.ico', + '/logo-192.png', + '/logo-512.png', + '/logo-badge-72.png', + '/logo-maskable-512.png', + '/logo-monochrome-512.png', + '/logo-monochrome-maskable-512.png', + '/manifest.webmanifest', + '/oauth-client-metadata.json', + '/og-image.png', + '/og-image-2.jpg', + '/robots.txt', + '/version.json', + ].forEach((path) => { + lines.push( + path, + ' ! Cache-Control', + ' Cache-Control: public, max-age=0, must-revalidate', + ); + }); + lines.push( + '/assets/*', + ' ! Cache-Control', + ' Cache-Control: public, max-age=31536000, immutable', + ); + fs.writeFileSync( + resolve(__dirname, 'dist/_headers'), + `${lines.join('\n')}\n`, + ); }, }, SENTRY_AUTH_TOKEN &&