How should a webserver dish up XHTML? There’s been a fair bit of discussion posted in many places all over the Internet, but here is the abstract from the W3C:
This document summarizes the best current practice for using various Internet media types for serving various XHTML Family documents. In summary,
application/xhtml+xmlshould be used for XHTML Family documents, and the use oftext/htmlshould be limited to HTML-compatible XHTML 1.0 documents.application/xmlandtext/xmlmay also be used, but whenever appropriate,application/xhtml+xmlshould be used rather than those generic XML media types.
What does this mean then? Well, as I use XHTML1.1 throughout, so according to the spec, I should always send such documents as application/xhtml+xml. However, at time of writing, the only browser which explicitly supports this media type is basically limited to Gecko based browsers, such as Mozilla.
Browsers such as Internet Explorer have no idea what to do with them, and will prompt for saving the file locally. Expected behaviour for unknown media types, but not a lot of good for effectively browsing a website.
Serving as generic XML, i.e.: application/xml, Internet Explorer would either show the document tree, or fail with an error along the lines of being unable to style the XML.
There is infact a test suit along with results from a number of browsers collated by Masayasu Ishikawa.
With further reading I decided to detect if application/xhtml+xml was an explicitly supported media type for the user-agent. If it was, excellent, send it as that; otherwise, “break” the XHTML1.1 specification, and fall back on to XHTML1.0 Transitional, and send content as text/html.
This worked very well, although there had to be minor corrections to the stylesheets as when a conforming user-agent is in the stricter X(HT)ML rendering mode, the <body> tag is no longer “magic” as it was in older HTML specifications. It’s behaviour relative to <html> is similar to a <div> nested within <body>.
So, my pages have been updated, if there’s anything awry, refresh your page. If it’s still FUBAR, let me know how it’s not working for you. :D