强制浏览器刷新 CSS、JavaScript 等 [英] Force browser to refresh CSS, JavaScript, etc

查看:36
本文介绍了强制浏览器刷新 CSS、JavaScript 等的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过 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.

推荐答案

通用解决方案

Ctrl + F5(或 Ctrl + Shift + R)强制重新加载缓存.我相信 Mac 使用 Cmd + Shift + R.

General solution

Pressing Ctrl + F5 (or Ctrl + Shift + R) to force a cache reload. I believe Macs use Cmd + Shift + R.

在 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 的缓存可以通过使用 F12 打开开发者工具,点击右下角的齿轮图标并在设置对话框中选择禁用缓存来禁用,如下所示:

Chrome

Chrome's cache can be disabled by opening the developer tools with F12, 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 等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆