Advanced Search

Results 1 to 4 of 4

Thread: Dynamic Ajax Content - caching problem

  1. #1
    Join Date
    Feb 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Dynamic Ajax Content - caching problem

    Dynamic Ajax Content script
    http://www.dynamicdrive.com/dynamici...jaxcontent.htm

    I've recently started using the above script to create dynamic content on one of my websites. It works very well in Firefox, but I'm having problems in IE and Opera.

    Basically the website is a random fortune cookie generator - a very stripped down test version can be seen at http://fortunecookie.rleeden.no-ip.com/ajax.php.

    In Firefox everytime you click the Fortune link a new fortune cookie is displayed - the php script fortune.php generates a new fortune. But this doesn't happen in IE or Opera as the output from the fortune.php script is getting cached. I can see from my apache logs - the fortune.php script is only called once. I can also see this when clearing my IE cache, a new fortune is displayed.

    Anybody know how to prevent this caching problem? Any help would be appreciated.

  2. #2
    Join Date
    Feb 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Further to the above, I've tried the same website from my home PC and the results are different than from my office PC. Firefox and IE both work fine, but Opera still doesn't work.

    I'm not sure what the difference is. I'm not using a proxy at work so that can't be it. Anybody any ideas? Anybody know how I can ensure that the output from fortune.php isn't cached?

  3. #3
    Join Date
    Feb 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Sorry, to be adding a third post to a thread that I started, but I've fixed the problem. Using PHP headers seems to have solved the problem.

    i.e. putting the following lines at the very top of my fortune.php script:

    <?php
    header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
    ?>

  4. #4
    Join Date
    Aug 2004
    Posts
    9,864
    Thanks
    3
    Thanked 960 Times in 949 Posts
    Blog Entries
    15

    Default

    Thanks for the tip. Another way to bust cache is to modify the line:

    Code:
    page_request.open('GET', url, true)
    inside the ajax script to something like:

    Code:
    page_request.open('GET', url+"?bustcache="+new Date().getTime(), true)
    This adds a constantly changing number to the query, busting cache in IE.

Bookmarks

Posting Permissions

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