From 0c885dc6115cf8093bb93916cee34aba8478dbb6 Mon Sep 17 00:00:00 2001 From: Zhang Minghan Date: Wed, 4 Oct 2023 10:24:31 +0800 Subject: [PATCH] update caching config --- app/vite.config.ts | 54 +++++++++++----------------------------------- 1 file changed, 13 insertions(+), 41 deletions(-) diff --git a/app/vite.config.ts b/app/vite.config.ts index 832f926..4a11f45 100644 --- a/app/vite.config.ts +++ b/app/vite.config.ts @@ -37,46 +37,7 @@ export default defineConfig({ swDest: 'dist/sw.js', skipWaiting: true, clientsClaim: true, - runtimeCaching: [{ - urlPattern: new RegExp('^https://fonts.googlefonts.cn/(.*)'), - handler: 'CacheFirst', - options: { - cacheName: 'google-fonts', - expiration: { - maxEntries: 3600, - } - } - }, - { - urlPattern: new RegExp('^https://fonts.gstatic.googlefonts.cn/(.*)'), - handler: 'CacheFirst', - options: { - cacheName: 'google-fonts-gstatic', - expiration: { - maxEntries: 3600, - } - } - }, - { - urlPattern: new RegExp('https://cdn.zmh-program.site/(.*)'), - handler: 'CacheFirst', - options: { - cacheName: 'cdn', - expiration: { - maxEntries: 3600, - } - } - }, - { - urlPattern: new RegExp('https://cdn.jsdelivr.net/(.*)'), - handler: 'CacheFirst', - options: { - cacheName: 'cdn-jsdelivr', - expiration: { - maxEntries: 3600, - } - } - }, + runtimeCaching: [ { urlPattern: /\.(?:png|gif|jpg|jpeg|svg|webp)$/, handler: 'CacheFirst', @@ -86,7 +47,18 @@ export default defineConfig({ maxEntries: 7200, } } - }], + }, { + urlPattern: new RegExp('^https://open.lightxi.com/'), + handler: 'CacheFirst', + options: { + cacheName: 'lightxi-cdn', + expiration: { + maxEntries: 7200, + maxAgeSeconds: 60 * 60 * 24 * 30, + } + } + } + ], } }), ],