1

I have seen many websites that include at their JavaScript and CSS external resources things like this:

filename.js?v=3cc1b79c2abb

And:

filename.css?v=7bbb71ecd5eb

The "?v=..." things at the end... What is this? And for what is this useful?

Thank you! Cheers :)

3
  • 1
    To prevent caching, i think... Commented Feb 15, 2014 at 12:47
  • Keyword: Cache breaker. Commented Feb 15, 2014 at 12:47
  • It should be noted that proxy servers may not like such query strings. I prefer to have /path/to/file.js/t=1234567 with the file's modification time there. The server then uses mod_rewrite to strip off the modification time. This ensures compatibility with proxies and even old versions of browsers. Commented Feb 15, 2014 at 12:51

4 Answers 4

4

These are a form of "Cache Busting" - they force the browser to download the latest version of the file, rather than taking a chance at loading an old file from cache.

Sign up to request clarification or add additional context in comments.

1 Comment

+1 - Slightly faster to answer, but you also typed out a coherent sentence unlike the other answer...
1

There is something more deeper - why do we need cache busting?

For efficiency sake we have to make the browser cache the resource files. For that to work we set last modified date as a very old date (say, 01-Jan-1970 00:00:00.000) and expiry date long into the future. These 2 things will make the browser cache the files so that they are not requested from the server again. That is very efficient. However, that causes a problem when you update the application. None of the resources will be downloaded again! To work around that we configure the build tool to append a version number query string unique to the build at the end of resource URLs. It is typical to use build timestamp or a uuid or the source repository version number (in case of version control tools like SVN which give a unique version number to every commit) as the version number string appended to the end of the resource URLs. That forces the browser to download new version whenever the application is updated.

Comments

0

This is your own version/keyword v=7bbb71ecd5eb of js and css, After use this, there would not be cache in browser with your older javascript and css.

Which means your new update of css and javascript would be applied without any cache.

Comments

0

It's to force the browser to download the file instead of getting it from cache.

For example, you have this url with css : styles.css?v=blablabla, but later you change css and want to have these changes to be seen instantly (instead of waiting when browser cache will expire or forcing user to press Ctrl + F5) you change it to something like styles.css?v=otherblablabla. Browser sees it as different url so it have to download it.

It's just a parameter in query string, and because the url points to static resource, these parameters are ignored by web server. You could also see something like this image.png?1392469113262. It's just a parameter named 1392469113262 that has no value. image.png is static resource so this parameter will be ignored by server. These numbers are usually some timestamp and it's the often the best way to force browser to not cache image (or any other resource).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.