Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jan 2005
    Posts
    140
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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!

  • #2
    Regular Coder
    Join Date
    Jul 2007
    Location
    UK
    Posts
    223
    Thanks
    0
    Thanked 14 Times in 14 Posts
    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.

  • #3
    Regular Coder
    Join Date
    Jan 2005
    Posts
    140
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What about using the no cache in HTML? Will this work?

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

  • #4
    Regular Coder
    Join Date
    Jul 2007
    Location
    UK
    Posts
    223
    Thanks
    0
    Thanked 14 Times in 14 Posts
    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" />


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •