diff --git a/vite.config.js b/vite.config.js index e1784915..c54f6eb5 100644 --- a/vite.config.js +++ b/vite.config.js @@ -27,6 +27,17 @@ export default defineConfig({ '*.{js,css,html,png,svg,jpg,webp}', ], runtimeCaching: [ + { + urlPattern: /\/(sw\.js|registerSW\.js|manifest\.webmanifest)$/, // sw 文件 + handler: 'NetworkFirst', + options: { + cacheName: 'critical-assets', + expiration: { + maxEntries: 3, + maxAgeSeconds: 4 * 60 * 60, // 4 小时 + }, + }, + }, { urlPattern: /\.(?:png|jpg|jpeg|svg|webp|woff|woff2)$/, // 图片文件 handler: 'CacheFirst',