为什么要添加版本号到CSS文件路径?

前端之家收集整理的这篇文章主要介绍了为什么要添加版本号到CSS文件路径?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我注意到一些网站将版本号(特别是)放在CSS文件路径中。例如:
<link rel="stylesheet" type="text/css" href="style.css?v=12345678" />

放置版本号的主要目的是什么?如果目的是记住上次CSS文件的更新时间,CSS文件中的版本号是不是作为注释添加的?

解决方法

http://html5boilerplate.com/docs/Version-Control-with-Cachebusting/

What is ?v=1″ ‘?v=1’ is the JavaScript/CSS Version Control with
Cachebusting

Why do you need to cache JavaScript CSS? Web page designs are getting
richer and richer,which means more scripts and stylesheets in the
page. A first-time visitor to your page may have to make several HTTP
requests,but by using the Expires header you make those components
cacheable. This avoids unnecessary HTTP requests on subsequent page
views. Expires headers are most often used with images,but they
should be used on all components including scripts,stylesheets etc.

How does HTML5 Boilerplate handle JavaScript CSS cache? HTML5
Boilerplate comes with server configuration files: .htacess,
web.config and Nginx.conf. These files tell the server to add
JavaScript CSS cache control.

When do you need to use version control with cachebusting?
Traditionally,if you use a far future Expires header you have to
change the component’s filename whenever the component changes.

How to use cachebusting? If you update your JavaScript or CSS,just update the “?v=1” to “?v=2”,“?v=3” … This will trick the browser think you are trying to load a new file,therefore,solve the cache problem.

原文链接:/css/218935.html

猜你在找的CSS相关文章