How to Use ?v= Version Query Strings for JS and CSS Files

  1. <span style="font-size:14px;">CSS and JS with parameters (in the form of .css?v= and .js?v= or .css?version= and .js?version= )  
  2.   
  3. <script type=”text/javascript” src=”jb51.js?version=1.2.6″></script>  
  4. <link rel=’stylesheet’ href=’base.css?version=2.3.3′ type=’text/css’ />  
  5.   
  6.   
  7. There are two possible reasons for using parameters:  
  8.   
  9.   
  10. First, the script does not actually exist as a static file but is dynamically generated on the server side, so a version number is appended to distinguish it.  That is, the code above is equivalent to  
  11. <script type=”text/javascript” src=”jb51.js”></script>  
  12. <link rel=’stylesheet’ href=’base.css’ type=’text/css’ />  
  13.   
  14.   
  15. However, the browser will treat it as a specific version of that file!  
  16.   
  17.   
  18. Second, the client browser caches these CSS or JS files. Therefore, each time you upgrade the JS or CSS file, changing the version number will force the client browser to re-download the new JS or CSS file, serving the purpose of busting the cache. You may have noticed that sometimes after modifying styles or scripts, refreshing the page shows no change; this is because the client has cached the CSS or JS file. Hence, adding parameters is definitely beneficial!  
  19. The second scenario is the most common, though both can coexist simultaneously. 

Leave a Comment

Your email address will not be published.