...

View Full Version : Don't Cache Javascript/Drop Down Menu Contents



dlg0351
08-27-2007, 02:33 PM
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!

mcjwb
08-27-2007, 07:55 PM
I think you need to make the html page none cachable. This is done server side, in php it would be:


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

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.

dlg0351
08-27-2007, 09:55 PM
What about using the no cache in HTML? Will this work?

<META HTTP-EQUIV="Pragma" CONTENT="no-cache">

mcjwb
08-27-2007, 10:06 PM
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" />



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum