我有一个PHP网站,标签中包含很多JS和CSS文件。问题是每当我更新任何JS或CSS然后打开我的网站时,chrome仍在加载旧版本的JS,CSS。我知道客户端我们可以通过Ctrl + Shift + R强制刷新,但是它太难以指示我的网站用户每次都这样做。
我试过这些但仍然没有运气。所以请建议一种强制浏览器每次从我的服务器重新加载JS而不是缓存的方法。
<meta http-equiv="cache-control" content="no-cache"> <!-- tells browser not to cache -->
<meta http-equiv="expires" content="0"> <!-- says that the cache expires 'now' -->
<meta http-equiv="pragma" content="no-cache"> <!-- says not to use cached stuff, if there is any -->
&#13;
答案 0 :(得分:0)
试试这个
<?php
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
?>
答案 1 :(得分:0)
添加像这样的版本ID,例如:/ js / example.js?$ versionid,如果您为调试执行此操作,则可以在开发人员工具中禁用chrome缓存