Browser Caching JavaScript Files – Lets force it to update!

angry_dog

Ever have a situation where you have to push a new JavaScript file but know you have users that might have it cached, or tired of having to refresh the page to get the latest JavaScript file?

I ran across this issue today and found a nice solution that worked as I needed it to.

As part of the src line in your call to the JavaScript file add a version to the end of it using ?VersionNumber as shown below:

<script type="text/javascript" src="filename.js?0001"></script>

Each time a change is made simply change the version number and no more having to fight JavaScript file caching.

Hope you find this helpful, I know I did. Have a better solution? I would love to hear about it, please leave a comment.

Leave a Reply