Friday, April 29, 2011

Html / php page being cached (client side) when it should not be

URL is here: http://www.thexsoft.com/DownloadFolder/download.php?file=P2PTransfer

This page is basically a way for me to have set url to download a certain problem i published. This page should never ever be cached, but it seems to be caching still.

I have set the following items:

<meta http-equiv="expires" content="0" >
<meta http-equiv="cache-control" content="no-cache" >
<meta http-equiv="pragma" content="no-cache" >
<meta http-equiv="Content-type" content="text/html;charset=UTF-8" >

The html code on the page validates 100% when i don't have the fastclick.net ad code in, but i keept it in now because it normally is in.

From stackoverflow
  • Pragma: no-cache prevents caching only when used over a secure connection (https). A Pragma: no-cache META tag is treated identically to Expires: -1 if used in a non-secure page. The page will be cached but marked as immediately expired.

    http://support.microsoft.com/kb/234067

    <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
    <META HTTP-EQUIV="Expires" CONTENT="-1">
    
    DaNieL : Does this trick works even for the CSS on the page?
    Eddie : I believe that you're incorrect about "pragma: no-cache" only preventing caching for HTTPS connections, unless you are talking about how some very specific version of some browser acts.
    apphacker : @DaNiel CSS doesn't belong in the same place as the markup, especially when you're worried about caching issues.
    Emre : @Eddie this is how IE works. You can check it out here http://support.microsoft.com/kb/234067
  • Yes, in some circumstances browsers cache aggressively, especially IE6. You need to check the http headers your server is sending, and if that isn't the issue try a cachebusting URL (insert a random/timebased get variable) to make the browser think it's a new URL.

  • I checked your headers using Firebug:

    Cache-Control: max-age=1209600
    Expires: Tue, 28 Apr 2009 18:49:15 GMT
    

    In PHP you can send HTTP headers with header().

    header('Pragma: no-cache');
    header('Expires: -1');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    
    Emre : I think you should use header('Cache-Control: no-cache'); see this page http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

0 comments:

Post a Comment