caching

A

ABC

I have an html page that has a javascript file included as well, with
the src == my.js. The problem is my page gets cached, which I want
and my js file gets cached, which I don't want. Is there a way to
just refresh the javacript file?

thks

ABC
 
A

Andy Fish

If you just want to refresh the js during development and test, control-f5
seems to work in IE

If you want it never to be cached in the production environment, you'll need
to get the web server to generate a no-cache HTTP directive. you'll need to
refer to the documentation for your web server on that one.

Andy
 
G

Grant Wagner

Andy said:
If you just want to refresh the js during development and test, control-f5
seems to work in IE

If you want it never to be cached in the production environment, you'll need
to get the web server to generate a no-cache HTTP directive. you'll need to
refer to the documentation for your web server on that one.

Andy

One of the ways to deal with this is something like:

<script type="text/javascript" src="my.js?version=200308070934"></script>

When you change my.js, change the HTML containing the reference to it and upload
them both. This can be bothersome if you use the script in many HTML files,
there are two other options to this:

1) server-side includes: put the <script ...> tag in another file and use SSI to
include that file on each page you want the script to appear on. Then you change
the "version" value above in a single place and it will take effect on all pages

2) client-side "includes": put

document.write('<script type="text/javascript"
src="my.js?version=200308070934"><\/script>');

in /another/ script file ("myWrapper.js" or something), then include that one on
your pages. If you never want your file cached you could use:

document.write('<script type="text/javascript" src="my.js?timestamp=' +
(new Date()).getTime() +
'"><\/script>');

--
| Grant Wagner <[email protected]>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/author/dhtml/reference/dhtml_reference_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 6/7 and Mozilla
* http://www.mozilla.org/docs/web-developer/upgrade_2.html
 

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
474,079
Messages
2,570,573
Members
47,205
Latest member
ElwoodDurh

Latest Threads

Top