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

Asked

Viewed 1,120 times

18

What it’s for and when to use

js? v=123(example)

css file? v=123(example)

What benefits and how the browser interprets this

2 answers

15


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 picks up the cache. But if you change the file on the server, the browser doesn’t know it, and keeps using the old version.

When passing any parameter at the end of the file, you change the URL, and the browser starts to consider that it is a different file. So download the new file, and cache it. To force the browser never cache, usually use a timestamp as a parameter. This is useful when developing a website. If you always pass the current timestamp on a production site, you completely cancel the browser cache, and the site loading will be a little slower, since the cache will not be used even when it could be.

6

Usually this is done, using some back-end support 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.

  • 1

    This does not slow down loading?

  • To my knowledge, it does not influence performance, and prevents the client from seeing old changes, by always loading the latest version of the file.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.