Css文件缓存

前端之家收集整理的这篇文章主要介绍了Css文件缓存前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个系统,其中缓存max-age设置为0并且存在问题,当我在我的style.css中进行了一些更改时,无法对客户端进行更改.浏览器将使用旧的缓存版本的CSS.
我有一个简单的问题:将css文件命名为style.css?123会被缓存为新的吗?

解决方法

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

Google Web Fundamentals在HTTP cache optimization上有一篇很棒的文章.特别是标题为“使缓存的响应失效和更新:”的部分.

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.

请注意,指纹不需要是序号.只要碰撞风险有限,任何值 – 哈希,版本等 – 都会发生.

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

原文链接:https://www.f2er.com/css/214847.html

猜你在找的CSS相关文章