react vue 单页面应用 部署 缓存问题
·
禁用 HTML 文件的缓存
在子应用的服务器(如 Nginx、Express、Spring Boot 等)中,对 index.html 设置禁止缓存:
Nginx 示例:
location = /index.html {
add_header Cache-Control "no-cache, no-store, must-revalidate";
add_header Pragma "no-cache";
add_header Expires "0";
}
Express 示例:
app.use((req, res, next) => {
if (req.url.endsWith('.html')) {
res.setHeader('Cache-Control', 'no-cache, no-store, must-revalidate');
res.setHeader('Pragma', 'no-cache');
res.setHeader('Expires', '0');
}
next();
});更多推荐



所有评论(0)