From 4347983fc7c135d641429da46dbaaeb4822ffaf7 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Fri, 4 Jul 2025 16:57:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0vite.config.ts=EF=BC=8C?= =?UTF-8?q?=E6=89=A9=E5=B1=95=E7=BC=93=E5=AD=98=E7=AD=96=E7=95=A5=E4=BB=A5?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=9B=B4=E5=A4=9A=E6=96=87=E4=BB=B6=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E5=92=8CAPI=E8=AF=B7=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vite.config.ts | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/vite.config.ts b/vite.config.ts index bdc3c953..070c8868 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -52,7 +52,7 @@ export default defineConfig({ srcDir: 'src', filename: 'service-worker.ts', workbox: { - globPatterns: ['**/*.{js,css,html,ico,png,svg,jpg,jpeg}'], + globPatterns: ['**/*.{js,css,html,ico,png,svg,jpg,jpeg,webp,woff,woff2,ttf,otf,eot}'], runtimeCaching: [ { urlPattern: /\.(?:js|css|html)$/, @@ -62,13 +62,47 @@ export default defineConfig({ }, }, { - urlPattern: /\.(?:png|jpg|jpeg|svg|ico)$/, + urlPattern: /\.(?:png|jpg|jpeg|svg|ico|webp|avif|gif|bmp|tiff)$/, handler: 'CacheFirst', options: { cacheName: 'image-cache', expiration: { - maxEntries: 100, - maxAgeSeconds: 30 * 24 * 60 * 60, + maxEntries: 200, + maxAgeSeconds: 30 * 24 * 60 * 60, // 30天 + }, + }, + }, + { + urlPattern: /\.(?:woff|woff2|ttf|otf|eot)$/, + handler: 'CacheFirst', + options: { + cacheName: 'font-cache', + expiration: { + maxEntries: 50, + maxAgeSeconds: 365 * 24 * 60 * 60, // 1年 + }, + }, + }, + { + urlPattern: /\/api\/v1\/.*$/, + handler: 'NetworkFirst', + options: { + cacheName: 'api-cache', + networkTimeoutSeconds: 10, + expiration: { + maxEntries: 500, + maxAgeSeconds: 24 * 60 * 60, // 24小时 + }, + }, + }, + { + urlPattern: /^https:\/\/image\.tmdb\.org\/.*$/, + handler: 'CacheFirst', + options: { + cacheName: 'tmdb-image-cache', + expiration: { + maxEntries: 300, + maxAgeSeconds: 7 * 24 * 60 * 60, // 7天 }, }, },