What is the use and when to use version in .js and .css files?


What is the use and when to use

file.js? v = 123 (example)

file.css? v = 123 (example)

What benefits and how the browser interprets this

asked by anonymous 20.11.2014 / 12:04

2 answers


This is done to prevent the browser from using a cached version of the file. If your site calls the same JS or CSS on multiple pages, the browser downloads those files from the server only once, and when you need them again, it takes you from the cache. But if you change the file on the server, the browser does not know this, and it continues using the old version.

By passing any parameter at the end of the file, you change the URL, and the browser now considers it to be a different file. So, download the new file, and cache it. To force the browser never to cache, usually a timestamp is used as a parameter. This is useful when developing a website. If you ever pass the current timestamp on a production site, you completely override the browser cache, and the site load will slow down a bit, since the cache will not be used even when it might be.

20.11.2014 / 12:16

Usually this is done, using some support back-end language, to be modifying the timestamp parameter at the end of the file, for example:

<link href="css/application.css?1305608333" media="screen" rel="stylesheet" type="text/css" />
<script src="jquery/jquery-1.1.11.min.js?1305599721" type="text/javascript"></script>

Forcing the browser to always load the latest version of the file, avoiding cache problems.

20.11.2014 / 12:09