Internet Explorer and pretty much all other modern web browsers make use of silent caching in order to streamline user experience. Of course, caching is a marvellous tool when needed, but also a frustrating one when you don’t want it turned on. Enter the humble .js javascript include file.

Now IE likes to cache javascript .js file includes, but unfortunately unlike normal web pages, getting it to refresh its cached copy can sometime prove to be quite difficult to achieve.

So here is the solution then.

Simply add a GET variable to the declaration.

If you never want the file to be cached, attach a randomly generated GET variable to the .js declaration for each page load. If you want to control when it gets refreshed, add a GET variable that you change only when you make actual changes to the .js file itself.

Essentially what happens is that IE recognises the URL as a single string, meaning that if the GET variable has changed, the string’s identity has changed, meaning a brand new URL and thus something it will need to go and collect from the internet.

So how does one’s .js file include look now?

<script type=”text/javascript” src=”myscript.js?ver=1″></script>

Simple, but very effective and well worth jotting down.