How to avoid external js file being cached ?

H

Homer J. Simpson

Hi there,
Does anyone know a working tip to avoid an external js file being cached,
whathever the client cache policy is ?

Thanks in advance,
J. Philippe
 
K

Kiran Makam

Try this,

<script>
var dt = (new Date()).getTime();
document.write( "<scr"+"ipt src='file.js?time="+dt+"'></scr"+"ipt>" );
</script>

Idea behind the code is to fool the browser with a different url every
time the page loads.
I have not tested, see if it works.

- Kiran Makam
 
H

Homer J. Simpson

Kiran,

It seems to works perfectly.
Just have to modify all my pages to introduce it....

Thanks for your answer.
J.Philippe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top