What does appending “?v=1” to CSS and Javascript URLs in link and script tags do?
来源:互联网 发布:阿里云 usb调试 编辑:程序博客网 时间:2024/06/01 07:39
https://stackoverflow.com/questions/3466989/what-does-appending-v-1-to-css-and-javascript-urls-in-link-and-script-tags-do
Question:
I have been looking at a HTML 5 boilerplate template (from http://html5boilerplate.com/) and noticed the use of "?v=1"
in URLs when referring to CSS and Javascript files.
- What does appending
"?v=1"
to CSS and Javascript URLs in link and script tags do? - Not all Javascript URLs have the
"?v=1"
(example from the sample below:js/modernizr-1.5.min.js
). Is there a reason why this is the case?
Sample from their index.html
:
<!-- CSS : implied media="all" --><link rel="stylesheet" href="css/style.css?v=1"><!-- For the less-enabled mobile browsers like Opera Mini --><link rel="stylesheet" media="handheld" href="css/handheld.css?v=1"><!-- All JavaScript at the bottom, except for Modernizr which enables HTML5 elements & feature detects --><script src="js/modernizr-1.5.min.js"></script><!------ Some lines removed ------><script src="js/plugins.js?v=1"></script><script src="js/script.js?v=1"></script><!--[if lt IE 7 ]> <script src="js/dd_belatedpng.js?v=1"></script><![endif]--><!-- yui profiler and profileviewer - remove for production --><script src="js/profiling/yahoo-profiling.min.js?v=1"></script><script src="js/profiling/config.js?v=1"></script><!-- end profiling code -->
Answer: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
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/stackoverflow/all.css?v=c298c7f8233d">
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.
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.
- What does appending “?v=1” to CSS and Javascript URLs in link and script tags do?
- What do /deep/ and ::shadow mean in a CSS selector?
- what does router do and its purpose?
- what-is-the-bios-and-what-does-it-do
- What is DMA and what does it do?
- What does => and () => mean in Scala
- git fail, and what to do????
- What does dirname(__FILE__) and basename(dirname(__FILE__)) do?
- do what you want to do and be youself
- Rendering fast with GDI+ - What to do and what not to do!
- Self summary: What does typical CNN do and What is Soft-max?
- What does L2 L3 and L4 mean in Network
- What is SynchronizationContext, and what does it mean to capture and use it?
- What does ENABLE_BITCODE do in xcode 7?
- What does ContextLoaderListener do in Spring?
- What does [B >: A] do in Scala?
- What I Have Done In 2005 And What I Should Do In 2006
- What To Do and Not To Do When 'shutdown immediate' Hangs [ID 375935.1]
- Unique Paths
- 在AJAX返回结果中循环执行另一个AJAX
- Merge K Sorted List
- Unique Paths II
- Facebook Open Graph META Tags
- What does appending “?v=1” to CSS and Javascript URLs in link and script tags do?
- VirtualBox如何配置Bridge和Host-Only虚拟网卡
- Optimize Facebook Sharing
- Creating “Share This on Facebook/Twitter” Links
- 随笔20141103
- How To Set Up Twitter Cards
- java.net.SocketException: Broken pipe
- Get current URL in JavaScript?
- The Secret to Getting a Large Facebook Link Thumbnail