Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-27-2007, 01:33 PM   PM User | #1
dlg0351
Regular Coder

 
Join Date: Jan 2005
Posts: 140
Thanks: 0
Thanked 0 Times in 0 Posts
dlg0351 is an unknown quantity at this point
Question Don't Cache Javascript/Drop Down Menu Contents

I have a 3 drop down menus used in a form. Depending on what the selection is of the 1st drop down menu, the contents of the the 2nd and 3rd drop down menu can change.

I have all the contents of the drops down menus stored in an array in an external .js file. That way I can manage the content better and upload new .js files whenever I need to.

Since the contents of the .js file can change frequently, my question is how can I ensure that people using the form are always accessing the most up to date .js file without having them to refresh the page?

Any help is greatly appreciated!
dlg0351 is offline   Reply With Quote
Old 08-27-2007, 06:55 PM   PM User | #2
mcjwb
Regular Coder

 
Join Date: Jul 2007
Location: UK
Posts: 223
Thanks: 0
Thanked 14 Times in 14 Posts
mcjwb is an unknown quantity at this point
I think you need to make the html page none cachable. This is done server side, in php it would be:

Code:
header("cache-Control: post-check=0, pre-check=0", false); 
header("Pragma: no-cache"); 
header("Expires: Mon, 27 Aug 2007 00:00 GMT");//Some date in the past.
Alternatively you could add a query string, which just has some random data in, to the end of the js file name in your js include
Code:
echo '<script type="text/javascript" src="myFile.js?'.rand().'"></script>';
you should probably use a better random number generator for this, usually they incorprate the date and time or something.

Hope this helps.
__________________
Javascript Debugging Tools:
IE Script Debugger | IE Developer Toolbar | Fiddler || FF Firebug | FF Web Developer
mcjwb is offline   Reply With Quote
Old 08-27-2007, 08:55 PM   PM User | #3
dlg0351
Regular Coder

 
Join Date: Jan 2005
Posts: 140
Thanks: 0
Thanked 0 Times in 0 Posts
dlg0351 is an unknown quantity at this point
What about using the no cache in HTML? Will this work?

<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
dlg0351 is offline   Reply With Quote
Old 08-27-2007, 09:06 PM   PM User | #4
mcjwb
Regular Coder

 
Join Date: Jul 2007
Location: UK
Posts: 223
Thanks: 0
Thanked 14 Times in 14 Posts
mcjwb is an unknown quantity at this point
Yes that is the html equivalent.
As well as:
<meta HTTP-EQUIV="Expires" content="27 Aug 2007 00:00:00 GMT" />
<meta HTTP-EQUIV="Cache-Control" content="no-cache" />
__________________
Javascript Debugging Tools:
IE Script Debugger | IE Developer Toolbar | Fiddler || FF Firebug | FF Web Developer
mcjwb is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:29 PM.


Advertisement
Log in to turn off these ads.