IE 302 Redirect No-Cache Header Problem

James Camfield picture James Camfield · Dec 29, 2008 · Viewed 8.9k times · Source

A 302 Redirect is being returned after a post of information. This redirect is intended to reload the current page.

This all works fine, but IE adds No-Cache to the header:

Cache-Control: no-cache

We are using Squid to cache our content, and putting this in the header bypasses squid.
As this redirect is used quite often(there is no way around this), this increases load on our system substantially.

Firefox doesn't have this problem, it simply requests the redirected page without changing the header which is exactly what we want.

Is there anything we can do to stop IE from adding no-cache?

Answer

EricLaw picture EricLaw · Jul 18, 2009

Fascinating. This is indeed an IE issue with no direct workaround. The problem is that IE will unconditionally add a Cache-Control: no-cache request header (or a Pragma: no-cache request header if you have a proxy) to a HTTP POST request.

This was doubtless introduced in IE over a decade ago to accomodate buggy proxy servers which did not properly handle HTTP POST requests and would incorrectly return cached responses.

A quirk of IE is that when you redirect, the no-cache headers are re-added to the redirected request. Hence, in your case, your redirected request also sends the "no-cache" request header carried over from the POST request.

Unfortunately, there's no direct workaround for this. You could redirect IE users to an interstitial page that uses JavaScript to redirect them back to the original page. (Don't use META REFRESH though, because that ALWAYS sends no-cache requests).