Css文件缓存 [英] Css file caching

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

问题描述

我有一个系统,其中缓存的最大年龄设置为0,有问题,当我在我的style.css做了一些更改失败,不改变客户端。浏览器将使用css的旧高速缓存版本。
我有简单的问题:命名css文件为style.css?123将被缓存为一个新的?

I have a system where cache max-age is set to 0 and there is problem, when I have made some changes in my style.css fail the changes dont apear to client. Browser will use the old cached version of css. I have simple question: Does naming css file as style.css?123 will be cached as a new?

推荐答案

是的,向资源的URI添加唯一的查询字符串将强制客户端提取新鲜版本客户端不知道它只是以前缓存的资源的更新)。这称为指纹,通常使用CSS文件的时间戳或递​​增的版本号 1

Yes, adding a unique query string to the resource's URI will force the client to fetch a "fresh" version (since the client doesn't know that it's merely an update of a previously cached resource). This is known as fingerprinting and you typically use a timestamp or an incrementing version number1 of the CSS file.

Google Web Fundamentals有一篇关于 HTTP缓存的文章优化。特别是标题为无效和更新缓存的响应:的部分

Google Web Fundamentals has a great article on HTTP cache optimization. Especially the section titled "Invalidating and updating cached responses:"


两个世界:客户端缓存和快速更新?您更改资源的URL,并强制用户下载新的响应,只要其内容更改。通常,您可以通过在文件名(例如样式)中嵌入文件的指纹或版本号来实现此操作。 x234dff .css。

How do you get the best of both worlds: client-side caching and quick updates? You change the URL of the resource and force the user to download the new response whenever its content changes. Typically, you do this by embedding a fingerprint of the file, or a version number, in its filename—for example, style.x234dff.css.

请注意,指纹不需要是序列号。

Do note, that the fingerprint does not need to be a sequential number. Any value – hash, version, etc. – will do as long as the risk of collisions is limited.

> 1)这是在这里做的SO,例如 http://sstatic.net/js/global-login.js?v=12

1) This is what's done here on SO, e.g. http://sstatic.net/js/global-login.js?v=12

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

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