Monday, March 28, 2011

How to instruct web browsers NOT to cache pages?

I've got a caching problem with the Internet Explorer 6.0 and I want to instruct the browser not to cache the page he's requesting.

Further information: In my page, there's a random token that prevents reloading the site and posting the same information twice or more.

If you now bookmark this page, the browser has to be instructed to refresh the site, everytime he requests it.

Firefox 3.0.5 does this correctly, but IE 6.0 keeps the random token in cache.

I included following meta tags in the affected page:

<meta http-equiv="cache-control" content="no-cache, must-revalidate">
<meta http-equiv="expires" content="0">
<meta http-equiv="pragma" content="no-cache">

Any ideas? Thanks in advance!

From stackoverflow
  • Check what HTTP headers your server is sending, these can over ride what is in the meta section in the HTML.

    Adam Hawes : The meta section in the HTML isn't worth the bytes it takes to download - it's a purely optional set of tags that need not be processed by the browser. The cache headers in the response, however are not optional and do work.
  • This is a fairly well documented googleable problem, and probably duped several times here, but fwiw this is my standard block (C#):

    Response.AppendHeader("Cache-Control", "no-cache"); //HTTP 1.1
    Response.AppendHeader("Cache-Control", "private"); // HTTP 1.1
    Response.AppendHeader("Cache-Control", "no-store"); // HTTP 1.1
    Response.AppendHeader("Cache-Control", "must-revalidate"); // HTTP 1.1
    Response.AppendHeader("Cache-Control", "max-stale=0"); // HTTP 1.1 
    Response.AppendHeader("Cache-Control", "post-check=0"); // HTTP 1.1 
    Response.AppendHeader("Cache-Control", "pre-check=0"); // HTTP 1.1 
    Response.AppendHeader("Pragma", "no-cache"); // HTTP 1.0 
    Response.AppendHeader("Expires", "Wed, 09 Jun 1993 00:00:00 GMT"); // HTTP 1.0
    
    StingyJack : Thats a nice compendium
  • meta tags are ok - but go with the headers (annakata's answer)- they work better when proxies are involved - then check your headers with http://www.httpviewer.net

0 comments:

Post a Comment