software, programming, functional
home mail me! RSS (2.0) feed

AJAX and IE caching problems

I spent hours today trying to make IE 6.0 less intelligent. I.e., to get it not to cache the AJAX responses.

The first attempts, to include

HTML4STRICT:
  1. <meta http-equiv="Pragma" content="no-cache" />

in the head portion of the HTML sent back to the client was laughed at by IE 6.

So, I use a search engine called Google to assist me in finding what the problem could be.

The first thing that Dr. Google told me was that IE 4 and 5 handled my pragma as if it were

HTML4STRICT:
  1. <meta http-equiv="Expires" content="-1" />

and then the kind doctor went into delirium, mumbling about "needing Expires anyway", "not in IE6", "if Expires=-1, it does cache but immediately remove it from cache" and finally went totally incoherent with something about a 64k buffer being involved and that IE only cared about the pragma directive in the last such buffer filling.

Ok, I tried to follow his incoherent advices by putting the pragma both before the HTML body and after. Yes, you heard right! My response then looked like:

HTML4STRICT:
  1. <meta http-equiv="Pragma" content="no-cache" />
  2. </head>
  3. my cool AJAX response
  4. </body>
  5. <meta http-equiv="Pragma" content="no-cache" />
  6. </head>
  7. </html>

Of course this did not work.

It turns out that - at least in IE 6.0 - you need an HTTP header, a pragma will not do!

So, what did work was to set the HTTP header Cache-Control to no-cache. Remember this next time you use AJAX with MSIE.

Leave a Comment

You must be logged in to post a comment.