优化 Vite 配置,添加运行时缓存策略,确保静态资源和图像的高效加载

This commit is contained in:
jxxghp
2025-01-15 14:25:17 +08:00
parent 7fb78a86ba
commit 838dff4758

View File

@@ -34,7 +34,30 @@ export default defineConfig({
filename: 'service-worker.ts',
workbox: {
globPatterns: ['**/*.{js,css,html,ico,png,svg,jpg,jpeg}'],
navigateFallbackDenylist: [/.*\/api\/v\d+\/system\/logging.*/],
runtimeCaching: [
{
urlPattern: /\.(?:js|css|html)$/,
handler: 'StaleWhileRevalidate',
options: {
cacheName: 'static-resources',
},
},
{
urlPattern: /\.(?:png|jpg|jpeg|svg|ico)$/,
handler: 'CacheFirst',
options: {
cacheName: 'image-cache',
expiration: {
maxEntries: 50,
maxAgeSeconds: 30 * 24 * 60 * 60, // 缓存 30 天
},
},
},
],
navigateFallback: '/index.html', // 确保页面路由正确加载
navigateFallbackDenylist: [
/.*\/api\/v\d+\/system\/logging.*/,
],
},
injectManifest: {
rollupFormat: 'iife',