禁用浏览器缓存 html 的页面内容

一、前端设置

1.在html文件头部加上

  <meta http-equiv="Expires" content="0">
  <meta http-equiv="Pragma" content="no-cache">
  <meta http-equiv="Cache-control" content="no-cache">
  <meta http-equiv="Cache" content="no-cache">

2.访问 index.html 的时候给后边加个时间戳,比如 index.html??v=20220415

二、服务端设置

通过响应头设置浏览器禁用缓存

response.setDateHeader("Expires", 0);
// Set standard HTTP/1.1 no-cache headers.
response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
// Set IE extended HTTP/1.1 no-cache headers (use addHeader).
response.addHeader("Cache-Control", "post-check=0, pre-check=0");
// Set standard HTTP/1.0 no-cache header.
response.setHeader("Pragma", "no-cache");

 

posted @ 2022-04-15 15:43  heroljy  阅读(324)  评论(0编辑  收藏  举报