Changing and reloading included .js files

J

jodleren

Hi

I just came a problem with JS on a site - I updated my .js file for
the site, it is included as follows:

<link rel="stylesheet" href="whatever.css" type="text/css">
<script type="text/javascript" src="whatever.js"></script>

Problem: IE does not automatically reload the .js file (nor .css) but
uses a cached version - which caused the site to fail this morning.
I know users have to press F5 to reload, but is there a way to _force_
reload, so¨my (stupid) users do not have too?

WBR
Sonnich
 
B

Bart Van der Donck

jodleren said:
I just came a problem with JS on a site - I updated my .js file for
the site, it is included as follows:

 <link rel="stylesheet" href="whatever.css" type="text/css">
 <script type="text/javascript" src="whatever.js"></script>

Problem: IE does not automatically reload the .js file (nor .css) but
uses a cached version - which caused the site to fail this morning.
I know users have to press F5 to reload, but is there a way to _force_
reload, so¨my (stupid) users do not have too?

You could make the requested URI unique:

'whatever.js?' + (new Date()).getTime();

Or, if you're under Apache, you could try to manipulate the headers in
order to avoid caching:

http://httpd.apache.org/docs/2.0/mod/mod_expires.html

Hope this helps,
 
T

Thomas 'PointedEars' Lahn

jodleren said:
I just came a problem with JS on a site - I updated my .js file for
the site, it is included as follows:

<link rel="stylesheet" href="whatever.css" type="text/css">

Your stylesheet is irrelevant here. A stylesheet is not a script (at least
not in non-NN4).
<script type="text/javascript" src="whatever.js"></script>

Problem: IE does not automatically reload the .js file (nor .css) but
uses a cached version - which caused the site to fail this morning.
I know users have to press F5 to reload, but is there a way to _force_
reload, so¨my (stupid) users do not have too?

http://www.mnot.net/cache_docs/

Despite statements to the contrary, this works also with non-Apache servers.


PointedEars
 

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

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top