Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q565 How can I prevent an external *.js file from being cached?

irt.org | Knowledge Base | JavaScript | Source | Q565 [ previous next ]

Q565 How can I prevent an external *.js file from being cached?

I'm not sure if this will work - please let me know - but you might want to try the same trick that is used to reload an image fresh from the server and not from the browsers cache:

<script language="JavaScript"><!--
var now = new Date();
document.write('<script src="library.js?' + now.gettime() + '"><\/script>');
//--></script>

The following was submitted by si

The previous answer doesn't work & after lots of searching I have not found a clean way of doing this.

However, one workaround is to version your .js filenames so 'myscript.js' becomes 'myscript_v1.js'. When you are ready to upload a new release to the server, increment filenames & includes of modified js files. This is now considered a new file & won't be found in the cache. Voila!

Its a bit dirty, I know, but the end result is OK!

Feedback on 'Q565 How can I prevent an external *.js file from being cached?'


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.