且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

附加“?v = 1”链接和脚本标签中的CSS和Javascript URL?

更新时间:2023-12-05 19:13:28

这些通常是为了确保当网站更新为新版本时浏览器会获得新版本,例如作为我们构建过程的一部分,我们会有这样的:

These are usually to make sure that the browser gets a new version when the site gets updated with a new version, e.g. as part of our build process we'd have something like this:

/Resources/Combined.css?v=x.x.x.buildnumber

由于每次新的代码推送都会发生变化,客户端***抢占新版本, querystring。查看此页面(在此答案时)例如:

Since this changes with every new code push, the client's forced to grab a new version, just because of the querystring. Look at this page (at the time of this answer) for example:

<link ... href="http://sstatic.net/***/all.css?v=c298c7f8233d">

我认为,而不是一个版本号SO团队用一个文件哈希,这是一个更好方法,即使有新版本,浏览器只是在文件实际更改时强制抓取新版本。

I think instead of a revision number the SO team went with a file hash, which is an even better approach, even with a new release, the browsers only forced to grab a new version when the file actually changes.

这两种方法都允许你将缓存头设置为可笑的长时间,例如20年...但是当它改变时,你不必担心那么浏览器会看到不同的查询字符串,并将其视为不同的新文件。

Both of these approaches allow you to set the cache header to something ridiculously long, say 20 years...yet when it changes, you don't have to worry about that cache header, the browser sees a different querystring and treats it as a different, new file.