mirror of
https://github.com/ZeroCatDev/Classworks.git
synced 2025-09-05 01:19:23 +00:00
Enhance Vite configuration by refining caching strategies to only apply to same-origin requests for assets and PWA paths. This improves cache management and ensures that external requests are not inadvertently cached.
This commit is contained in:
parent
c79a850868
commit
3654e22fef
@ -38,7 +38,9 @@ export default defineConfig({
|
|||||||
navigateFallback: 'index.html',
|
navigateFallback: 'index.html',
|
||||||
runtimeCaching: [
|
runtimeCaching: [
|
||||||
{
|
{
|
||||||
urlPattern: ({ url }) => url.pathname.startsWith('/assets/'),
|
urlPattern: ({ url, sameOrigin }) => {
|
||||||
|
return sameOrigin && url.pathname.startsWith('/assets/');
|
||||||
|
},
|
||||||
handler: 'CacheFirst',
|
handler: 'CacheFirst',
|
||||||
options: {
|
options: {
|
||||||
cacheName: 'assets-cache',
|
cacheName: 'assets-cache',
|
||||||
@ -52,7 +54,9 @@ export default defineConfig({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
urlPattern: ({ url }) => url.pathname.startsWith('/pwa/'),
|
urlPattern: ({ url, sameOrigin }) => {
|
||||||
|
return sameOrigin && url.pathname.startsWith('/pwa/');
|
||||||
|
},
|
||||||
handler: 'StaleWhileRevalidate',
|
handler: 'StaleWhileRevalidate',
|
||||||
options: {
|
options: {
|
||||||
cacheName: 'pwa-cache',
|
cacheName: 'pwa-cache',
|
||||||
@ -66,8 +70,9 @@ export default defineConfig({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// 匹配除了上述规则外的所有请求
|
// 匹配当前域名下除了上述规则外的所有请求
|
||||||
urlPattern: ({ url }) => {
|
urlPattern: ({ url, sameOrigin }) => {
|
||||||
|
if (!sameOrigin) return false;
|
||||||
const path = url.pathname;
|
const path = url.pathname;
|
||||||
// 排除已经由其他规则处理的路径
|
// 排除已经由其他规则处理的路径
|
||||||
return !(path.includes('/assets/') || path.includes('/pwa/'));
|
return !(path.includes('/assets/') || path.includes('/pwa/'));
|
||||||
@ -85,7 +90,6 @@ export default defineConfig({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
],
|
],
|
||||||
additionalManifestEntries: [],
|
additionalManifestEntries: [],
|
||||||
clientsClaim: true,
|
clientsClaim: true,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user