1

I am currently testing a web site as the development goes on, and almost every time the client script is updated, I need to clear the browser cache for a new functionality to become available on the client due to the fact that the browser downloads the fresh compy of the .js file.

What if in production I roll out a new version of a script? How do I get the client browsers to get it as soon as it is uploaded to the server?

I am using an ASP.NET MVC 4 site.

3 Answers 3

1

Easiest way will be adding the version number to the script file(say script_1.6.js etc)

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

Comments

0

Rename the file to create versioning:

so

<script src="myscript.js"></script>

becomes

<script src="myscript-9-5-2012.js"></script>

Also per https://developers.google.com/speed/docs/best-practices/caching#LeverageProxyCaching

It's not recommended to use querystrings for versioning (ie. myscript.js?v=1.1.0) because specifically

Most proxies, most notably Squid up through version 3.0, do not cache resources with a "?" in their URL ...

Comments

0

The best way to stop your scripts from caching is to add a random querystring value at the end of each line. e.g.

 <script src="/path-to-your-script/script.js?v=0b1"></script>

This is great in development as your scripts never get cached, although in production you do really want the browser to cache the scripts to speed things up.

So for production, you would probably want to introduce some versioning like jquery for instance, jquery-1.8.0.js

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.