Add no-cache headers to index.html via custom Vite plugin

• Create noCachePlugin for Vite
• Add cache-control meta tags
• Inject headers into index.html
• Prevent browser caching issues
This commit is contained in:
yangdx 2025-07-25 22:03:25 +08:00
parent 4ae44bb24b
commit 93ce53394f

View file

@ -4,9 +4,21 @@ import { webuiPrefix } from '@/lib/constants'
import react from '@vitejs/plugin-react-swc'
import tailwindcss from '@tailwindcss/vite'
// A custom Vite plugin to add cache-control headers to index.html
const noCachePlugin = () => ({
name: 'no-cache',
transformIndexHtml(html: string) {
const cacheControlMeta = `
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />`;
return html.replace('</head>', `${cacheControlMeta}\n</head>`);
},
});
// https://vite.dev/config/
export default defineConfig({
plugins: [react(), tailwindcss()],
plugins: [react(), tailwindcss(), noCachePlugin()],
resolve: {
alias: {
'@': path.resolve(__dirname, './src')