为什么要添加版本号到CSS文件路径? [英] Why adding version number to CSS file path?

查看:126
本文介绍了为什么要添加版本号到CSS文件路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到一些网站把版本号(特别是)放在CSS文件路径。例如:

I noticed some websites put the version numbers (especially) in the CSS file path. For example:

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

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

What is the main purpose to put the version number? If the purpose is to remember when the CSS file was updated last time, shouldn't the version number added as a comment inside the CSS file?

推荐答案


什么是?v = 1'?v = 1'是JavaScript / CSS版本控制
Cachebusting

What is ?v=1" '?v=1' is the JavaScript/CSS Version Control with Cachebusting

为什么需要缓存JavaScript CSS?网页设计得到的是
更丰富和更丰富,这意味着更多的脚本和样式表在$ b $第一次访问你的页面的访问者可能需要做几个HTTP
请求,但是通过使用Expires头你使那些组件
可缓存,避免了后续页面上不必要的HTTP请求
视图。Expires头最常用于图像,但是
应该用于所有组件,包括脚本,样式表等。

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.

HTML5 Boilerplate如何处理JavaScript CSS缓存? HTML5
Boilerplate自带了服务器配置文件:.htacess,
web.config和nginx.conf。这些文件告诉服务器添加
JavaScript CSS缓存控件。

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.

什么时候需要使用带cachebusting的版本控制?
传统上,如果你使用一个很远的未来Expires标头,你必须
改变组件的文件名每当组件改变。

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.

如何使用cachebusting?如果您更新JavaScript或CSS,只需
将?v = 1更新为?v = 2,?v = 3...这将欺骗浏览器
试图加载一个新文件,因此,解决缓存
的问题。

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文件路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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