Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

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

You are here: irt.org | FAQ | JavaScript | Source | Q565 [ previous next ]

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?'

©2018 Martin Webb