问题描述
我正在通过 XAMPP 开发基于 WordPress 源代码的网站.有时我更改 CSS 代码、脚本或其他东西,我注意到我的浏览器需要时间来应用修改.这导致我使用多个浏览器来刷新一个,如果它不应用新样式,我会尝试第二个,并且总是这样.
I'm developing a website based on WordPress source code through XAMPP. Sometimes I change the CSS code, scripts or something else and I notice my browser takes time to apply the modifications. This leads me to use multiple browsers to refresh one and if it doesn't apply the new styles I try the second one and it's always this.
有什么办法可以避免这个问题吗?
There is some way of avoiding this problem?
有时我会在没有注意到之前的修改的情况下更改代码.
Sometimes I'm changing code without noticing the previous modifications.
推荐答案
通用解决方案
按 + (或 + + )强制重新加载缓存.我相信 Mac 使用 + + .
General solution
Pressing + (or + + ) to force a cache reload. I believe Macs use + + .
在 PHP 中,您可以通过使用标头将过期日期设置为过去的时间来禁用缓存:
In PHP, you can disable the cache by setting the expiration date to a time in the past with headers:
header("Expires: Tue, 01 Jan 2000 00:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
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");
铬
Chrome 的缓存可以通过使用 打开开发者工具,点击右下角的齿轮图标并在设置对话框中选择禁用缓存来禁用,如下所示:
Chrome
Chrome's cache can be disabled by opening the developer tools with , clicking on the gear icon in the lower right corner and selecting Disable cache in the settings dialog, like this:
在 URL 栏中键入 about:config
,然后找到标题为 network.http.use-cache
的条目.将此设置为 false
.
Type about:config
into the URL bar then find the entry titled network.http.use-cache
. Set this to false
.
这篇关于强制浏览器刷新 CSS、JavaScript 等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!