1

I'm currently working on a webapp and the Javascript is revised fairly often. However, the changes don't occur until the browser cache is refreshed manually. Is there a way to implement cache-refreshing automatically through code for Chrome? Thanks.

1
  • 2
    I never have this problem. Are you sure it's Chrome that is doing the caching, as opposed to your site? Commented Sep 29, 2011 at 16:18

1 Answer 1

8

You can put something like ?2352352 at the end of your JS file. So something like

<script src='myfile.js?20457207'></script>

Where the number randomizes, forcing the browser to think it's a different file.

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

4 Comments

This looks like a solution but I'm not sure what the implications are. So we're currently using TortoiseSVN. Does anyone know if there's a way to automatically have TortoiseSVN prepend a comment with the version# of the commit every time a new version is committed?
You would just need to update the html <script> each time you change a version. Or, you should be able to google and find a way to access revision number. Which you could probably inject in place of the random int. This may be useful.
A random number may be convenient during development, but in production a version number is a lot better, so the file can be cached as long as there is no new version. Using a random number, the file will never be cached, and downloaded at each page view, even if the js file has not been changed.
Very true. A random int will force it to pull as new each time.

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.