IE9 Standards Mode Accepts only text/css for stylesheets

I recently encountered a blog that isn’t looking right in IE9:

image

The site renders just fine in other browsers, and when the page is put into Compatibility View by ticking the icon in the address bar:

image

What’s going on here? It’s clear that a stylesheet isn’t being applied, but why not?

While IE9’s F12 Developer Console logs a notification if a server provides an incorrect MIME type for a stylesheet response, no explicit console notification is provided when the stylesheet download fails; developers will need to use the F12 Network tab or Fiddler to troubleshoot the download failure.

The root of the problem quickly becomes obvious when Fiddler is watching the traffic. For IE9 running in Standards Mode, the site is returning a HTTP/406 response to the browser for the key stylesheet:

image

When the stylesheet fails to download (see the red entry above), IE has no styles to apply and the user sees unstyled HTML.

What’s different about IE9 Standards Mode?

IE9 Standards Mode corrects a longstanding limitation whereby earlier versions of IE would improperly send an Accept: */* request header for all resources in a page. That header suggested that IE would be perfectly happy with any Content-Type returned by the server.

While always misleading, that is now outright wrong in IE9—for security and standards reasons, IE9 Standards Mode requires stylesheet responses have a text/css MIME type. If they do not, the browser will not attempt to load the response as a stylesheet. IE9 communicates this requirement to the server by specifying that it will only accept text/css responses when a HTTP request is made for a stylesheet.

It turns out that this server has a bug whereby it returns a HTTP/406 Not Acceptable response when the browser specifies that it will only accept a text/css response… in spite of the fact that the response content actually is text/css. A look at the response headers on the HTTP/406 response provides a clue as to what the problem may be:

HTTP/1.1 406 Not Acceptable
Server: Apache
Alternates: {"serendipity.css.php" 1 {type application/x-httpd-php}}
Vary: negotiate,Accept-Encoding
TCN: list
Content-Type: text/html; charset=iso-8859-1

The Alternates header suggests to me that the CSS file in question is generated by PHP, but the webserver software thinks that PHP files will always be served with an application/x-httpd-php MIME type. With this misunderstanding, the web server refuses to actually run the PHP file and thus never realizes that the PHP file will itself set the proper text/css MIME type.

With their Accept headers, Firefox, Chrome and Opera all imply that they will accept any MIME type for a stylesheet response, although like IE9 they too will not apply a stylesheet that bears an incorrect MIME type.

Internet Explorer 9 users can workaround the site’s bug by putting the site into Compatibility View. In Compatibility View, IE reverts to its legacy behavior of claiming to accept any MIME type for subdownload requests, and the server returns the response without complaint.

-Eric Lawrence