From dd70f9d886be8231861412ed89580a81204e7385 Mon Sep 17 00:00:00 2001 From: typist Date: Wed, 29 Oct 2025 14:49:06 +0800 Subject: [PATCH] feat: enhance caching strategies for Google Fonts - Added caching configurations for Google Fonts stylesheets and webfonts. - Implemented 'StaleWhileRevalidate' for stylesheets and 'CacheFirst' for font files to optimize loading and improve performance. --- vite.config.ts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/vite.config.ts b/vite.config.ts index c6e53ac..e444c06 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -43,6 +43,36 @@ export default defineConfig({ statuses: [0, 200] } } + }, + { + // Google Fonts 样式表缓存 + urlPattern: /^https:\/\/fonts\.googleapis\.com\/.*/i, + handler: 'StaleWhileRevalidate', + options: { + cacheName: 'google-fonts-stylesheets', + expiration: { + maxEntries: 10, + maxAgeSeconds: 60 * 60 * 24 * 365 // 1 年 + }, + cacheableResponse: { + statuses: [0, 200] + } + } + }, + { + // Google Fonts 字体文件缓存 + urlPattern: /^https:\/\/fonts\.gstatic\.com\/.*/i, + handler: 'CacheFirst', + options: { + cacheName: 'google-fonts-webfonts', + expiration: { + maxEntries: 30, + maxAgeSeconds: 60 * 60 * 24 * 365 // 1 年 + }, + cacheableResponse: { + statuses: [0, 200] + } + } } ], cleanupOutdatedCaches: true,