CSS文件preventing缓存 [英] Preventing Caching of CSS Files

查看:177
本文介绍了CSS文件preventing缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用PHP开发一个简单的网站。

I am developing a simple website using PHP.

开发配置: WAMP

生产配置: LAMP

测试时,我改变了我的CSS文件,但是当我重新加载页面我的浏览器(不知道)仍然使用旧的缓存CSS。

While testing, I changed my CSS file, but when I reload the page my browser(not sure) still uses the old cached css.

我做了一些google搜索,我发现我已经尝试了不同的解决方案。

I did some googling and found different solutions that I have already tried


  • 在CSS的结尾追加查询 CSS /的main.css?78923

  • 使用按Ctrl + R (在Firefox)来强制资源取

  • 禁用Firefox的缓存以及使用清除缓存 Firefox插件。

  • Appending a query at the end of css css/main.css?78923
  • Using Ctrl + R (in Firefox) to force fetching of the resource
  • Disabling Firefox caching as well as using the Clear Cache Firefox add-on.

当这一切都不工作,我做了一些更多的谷歌搜索,在那里我碰到一个堆栈页来(的这里),其中有人建议Apache的缓存资源。所以,问题是不会出现在Firefox,但服务器。这家伙还建议,我不明白一个解决方案(我是一个新手)

When none of this worked, I did some more googling, where I came across a stack page (here) where someone suggested that Apache caches the resources. So, the problem is not with the Firefox, but the server. The guy also suggested a solution that I did not understand (me being a newbie)

我的问题有两个部分:


  1. 这是真的,Apache的缓存资源? (我如何检查,如果我的呢?)

  2. 如何到$ P $从缓存pvent它

  1. Is it true that Apache caches resources? (How do I check if mine does?)
  2. How to prevent it from caching?

PS:复制和粘贴在堆栈的问题(一个,我上面有一个链接)的解决没有工作:(

PS: copying and pasting the solution in stack question (the one that I have above as a link) did not work :(

推荐答案

我碰到这个问题,跑了几次,通常通过调用我的CSS像这样来对生产场所的问题

I've ran across this problem a few times and usually over come the problem on production sites by calling my css like this

<link rel="stylesheet" type="text/css" href="style.css?v=1" />

当你推出一个更新只是改变了 V = 1 V = 2 ,这将迫使所有的你的用户的浏览器来获取新的样式表。这将为脚本文件正常工作。如果您在查看源代码谷歌你会发现他们使用这种方法为好。

When you roll out an update just change the v=1 to v=2 and it will force all of your users browsers to grab the new style sheets. This will work for script files as well. If you view source on Google you will notice they use this approach as well.

这篇关于CSS文件preventing缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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