Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Internet Explorer 9 ignoring no cache headers

I'm tearing my hair out over Internet Explorer 9's caching.

I set a series of cookies from a perl script depending on a query string value. These cookies hold information about various things on the page like banners and colours.

The problem I'm having is that in IE9 it will always, ALWAYS, use the cache instead of using the new values. The sequence of events runs like this:

  1. Visit www.example.com/?color=blue
  2. Perl script sets cookies, I am redirected back to www.example.com
  3. Colours are blue, everything is as expected.
  4. Visit www.example.com/?color=red
  5. Cookies set, redirected, colours set to red, all is normal
  6. Re-visit www.example.com/?color=blue
  7. Perl Script runs, cookies are re-set (I have confirmed this) but! IE9 retreives all resources from the cache, so on redirect all my colours stay red.

So, every time I visit a new URL it gets the resources fresh, but each time I visit a previously visited URL it retrieves them from the cache.

The following meta tags are in the <head> of example.com, which I thought would prevent the cache from being used:

<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE"> 
<META HTTP-EQUIV="EXPIRES" CONTENT="0">

For what it's worth - I've also tried <META HTTP-EQUIV="EXPIRES" CONTENT="-1">

IE9 seems to ignore ALL these directives. The only time I've had success so far in that browser is by using developer tools and ensuring that it is manually set to "Always refresh from server"

Why is IE ignoring my headers, and how can I force it to check the server each time?

like image 484
Andy F Avatar asked Nov 23 '11 09:11

Andy F


People also ask

How do I disable full header view cache?

When you're in Google Chrome, click on View, then select Developer, then Developer Tools. Alternatively, you can right click on a page in Chrome, then click Inspect. Click on the Network tab, then check the box to Disable cache. You can then close out of Developer Tools.

What is no-cache header?

The no-cache directive means that a browser may cache a response, but must first submit a validation request to an origin server.

How do I set HTTP headers for Cache-Control?

To use cache-control in HTML, you use the meta tag, e.g. The value in the content field is defined as one of the four values below. HTTP 1.1. Allowed values = PUBLIC | PRIVATE | NO-CACHE | NO-STORE.

When the value of Cache-Control is set to no-cache ie disable cache?

cache-control: no-cacheThis token is changed on the origin server whenever the resource is updated. When a user returns to a page with a 'no-cache' resource, the client will always have to connect to the origin server and compare the ETag on the cached resource with one on the server.


2 Answers

Those are not headers. They are <meta> elements, which are an extremely poor substitute for HTTP headers. I suggest you read Mark Nottingham's caching tutorial, it goes into detail about this and about what caching directives are appropriate to use.

Also, ignore anybody telling you to set the caching to private. That enables caching in the browser - it says "this is okay to cache as long as you don't forward it on to another client".

like image 55
Jim Avatar answered Oct 12 '22 23:10

Jim


Try sending the following as HTTP Headers (not meta tags):

Cache-Control: private, must-revalidate, max-age=0
Expires: Thu, 01 Jan 1970 00:00:00
like image 21
johnstok Avatar answered Oct 12 '22 23:10

johnstok