现在这个bug已经持续了很长时间。我已经尝试了一切来阻止缓存。以下stackoverflow链接上的所有内容:
Chrome - Disable cache for localhost only?
Disabling Chrome cache for website development
Using <meta> tags to turn off caching in all browsers?
How to prevent Browser cache for php site
How to control web page caching, across all browsers?
How to prevent http file caching in Apache httpd (MAMP)
我还试图右键点击Chrome上的重新加载按钮,然后选择reload page complete
和empty cache and reload page completely
。我使用PHPStorm作为IDE,但我也尝试切换到记事本++,以防PHPStorm没有正确保存文件。尝试在标题中设置时间戳,以便我对页面的请求不相同。我在localhost XAMPP上运行。任何解决方案/想法/猜测都非常受欢迎。
重新启动XAMPP实际上会清除缓存(或者至少强制浏览器重新加载内容)。我不知道为什么。提前致谢
我的PHP代码也被缓存了。当我编辑我的PHP代码并刷新页面时,它再次运行旧代码。这可能是因为浏览器仍然显示页面的缓存版本,但认为值得一提。
答案 0 :(得分:2)
这里没有太多信息;但你可能想看看你的php.ini,特别是你的revalidate_freq。开发时最好为0;但绝对不会超过2
秒的默认值。
答案 1 :(得分:1)
在根目录下创建.htaccess文件,并将以下代码放在.htaccess文件中。 检查服务器中是否启用了mod_rewrite(可选)。 添加它会停止缓存页面
#Initialize mod_rewrite
RewriteEngine On
<FilesMatch "\.(html|htm|js|css)$">
FileETag None
<IfModule mod_headers.c>
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 12 Jan 1980 05:00:00 GMT"
</IfModule>
</FilesMatch>
答案 2 :(得分:1)
请检查下面提到的解决方案,它会对你有帮助。
第1步:
在HTML head
标记中,您应添加下面提到的行。
<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"/>
因此,当用户访问您的网页时,每次从服务器获取新内容时都会这样做。
第2步:
通过使用.htaccess
,您可以阻止浏览器缓存100%的页面。
<filesMatch "\.(html|htm|js|css)$">
FileETag None
<ifModule mod_headers.c>
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
</ifModule>
</filesMatch>
第3步:
如果您的页面位于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");
header("Expires: 0");
如果不起作用,请告诉我。
答案 3 :(得分:0)
我安装了一个清除缓存的chrome扩展。我配置它用CTAL + Q清除缓存 - 所以刷新页面的F5或CTRL + R我使用此扩展 - 它解决了我的developin缓存问题(我使用聚合物框架 - 我和你有同样的问题) i use this extension
答案 4 :(得分:-1)
下次你可以在你的head标签中输入你的css文件名之后的字符串查询,例如“style.css?v = 3”。这样它就不会使用缓存来处理css文件。