From 364571cf4139c2abafc97fbaa0250acef08e6b0d Mon Sep 17 00:00:00 2001 From: jason5ng32 Date: Thu, 8 Aug 2024 02:34:01 +0800 Subject: [PATCH] Update Cache Strategy --- vite.config.js | 11 +++++++++++ 1 file changed, 11 insertions(+) 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',