1

I have a constant problem updating my javascript. I have tried most things to ensure that browsers do not cache my webapps such as using variables on the end of the src eg ?v1 etc and html tags but nothing works.

When I have to update my javascript in html, the browser automatically caches the old version and the new version doesn´t load...any tips???

yours, Rob

1
  • Do you ever want your script cached? Commented Feb 14, 2012 at 20:16

2 Answers 2

1

You are correct in what you are doing by assigning a different version to the script, that way the browser cant cache the javascript as it's making an entirly different request each time.

For example:

<script type="text/javascript" src="/site-script.js?<?php echo time(); ?>"></script>
<-- RENDERS -->
<script type="text/javascript" src="/site-script.js?1234567890"></script>
Sign up to request clarification or add additional context in comments.

Comments

0

Using variables when requesting the script should work as long as you change the string every time your JavaScript changes. For a development environment I would recommend to disable the browser cache entirely (e.g. by using the Firefox Web Developer addon which can do it on a per page basis). Also a full page refresh (normally CTRL + F5) should for your script files being reloaded as well.

2 Comments

The problem I find is that users do not know what ctrl + F5 does (or even exists). I had a case today where I the application starts from the index.html. To update the site I simply wrote a simple html "this site is being updated" page and named it index.html and renamed the real app index_.html. After it had been updated, people were ringing up asking why it was taking so long.....they were only seeing the cached version ...it had been ready at least 30mins.
In production, requesting files with version numbers should work just fine without a problem though. Of course you will have to change index.html for that as well. It also depends on the webserver settings.

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.