55

Just updated my site to newer, much more standards compliant design. My previous design was so rubbish that I had to use the IE=EmulateIE tag to force IE7 emulation.

Unfortunately, I believe that browsers may be caching this setting from previous visits, causing my new site (which looks great without the button pressed) to look rubbish again...

Is there any opposite tag that I could use, or some magic I can make PHP do to the HTTP headers disable caching of this setting?

gen_Eric
  • 223,194
  • 41
  • 299
  • 337
Jack Shepherd
  • 551
  • 1
  • 4
  • 3
  • 9
    You know what, I thought I'd read though all the previous questions on this topic, but the tab to the right of this one held the answer: Case Closed! – Jack Shepherd Jan 14 '10 at 14:25
  • 6
    Then post it as an answer and accept it - I needed the same info and almost missed the comment. Just don't forget to link to the "tab to the right" :) – AnonJr Jan 19 '10 at 12:38
  • 2
    You can do it as an actual HTTP header instead of the HTML. This is better, as no-nothings are less likely to copy and paste it into non-compatible sites. `header('X-UA-Compatible: IE=edge);` – TRiG Jun 22 '10 at 16:56
  • Argh. Spelling failure. know-nothings. – TRiG Jun 24 '10 at 17:07

4 Answers4

51

In the absence of an X-UA-Compatible http-equiv header, the compatibility mode is determined by the !DOCTYPE (or the absence of a !DOCTYPE, as the case may be). For a chart of which !DOCTYPE gives you which mode (in various browsers) see here:

http://hsivonen.iki.fi/doctype/ (You'll need to scroll down toward the bottom of the page.)

You can override this behavior by using a meta element to specify an X-UA-Compatible http-equiv header, like so: <meta http-equiv="X-UA-Compatible" content="IE=edge" >

(Note: IE=edge goes with the highest available version -- currently IE8 as of this posting -- or one can explicitly specify IE8.)

For more information, see here: http://msdn.microsoft.com/en-us/library/cc288325(VS.85).aspx

Tim Goodman
  • 23,308
  • 7
  • 64
  • 83
  • 7
    Rather than using an aribirarity large number for the IE version, it would be better to use the supported keyword 'edge' to alway force the latest version. – Michael Benny Jan 24 '10 at 19:50
  • @mbenny: Good point. I have updated the answer to reflect this. – Tim Goodman Jan 25 '10 at 00:51
  • 12
    It's noteworthy that the META tag must come before any SCRIPT tags in the HEAD section. – xero Jun 23 '10 at 17:20
  • 1
    You can also specify multiple version like in this example : See http://msdn.microsoft.com/en-us/library/jj676915(v=vs.85).aspx – Marshall777 Sep 17 '13 at 08:24
8

You can also set the X-UA-Compatible header in Apache, via the config or an .htaccess file using the code below. Credit goes to html5boilerplate.com

# ----------------------------------------------------------------------
# Better website experience for IE users
# ----------------------------------------------------------------------

# Force the latest IE version, in various cases when it may fall back to IE7 mode
# github.com/rails/rails/commit/123eb25#commitcomment-118920
# Use ChromeFrame if it's installed for a better experience for the poor IE folk

<IfModule mod_setenvif.c>
  <IfModule mod_headers.c>
    BrowserMatch MSIE ie
    Header set X-UA-Compatible "IE=Edge,chrome=1" env=ie
  </IfModule>
</IfModule>

<IfModule mod_headers.c>
#
# Because X-UA-Compatible isn't sent to non-IE (to save header bytes), we need to inform proxies that content changes based on UA
#
  Header append Vary User-Agent
# Cache control is set only if mod_headers is enabled, so that's unncessary to declare
</IfModule>
toneplex
  • 673
  • 5
  • 6
5

I know this post is old, but I find adding this to your .htaccess file:

Header set X-UA-Compatible "IE=edge"

...to be more manageable than adding it to pages.

Hope that helps someone.

jasonflaherty
  • 1,924
  • 7
  • 40
  • 82
5

IE will never cache the X-UA-Compatibility setting on its own. The only other possibility is that users of the site pressed the 'Compatibility View' button on the address bar before you had the X-UA-Compatbile meta tag set. Then your site's domain will appear in a list stored locally on the client's machine. I wrote a blog post about how site owners can prune their domains from that locally stored list if/when a site gets updated to be IE8 compatible. http://blogs.msdn.com/ie/archive/2009/07/01/ie-compatibility-list-pruning.aspx

Michael Benny
  • 428
  • 3
  • 8