禁用 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();
});
Logo

Agent 垂直技术社区,欢迎活跃、内容共建。

更多推荐