Delivering XHTML 1 documents over HTTP

I’ve been doing a bit of research this afternoon about how one is supposed to deliver XHTML documents which are correctly validated as either XHTML 1.0 or XHTML 1.1. From Sending XHTML as text/html Considered Harmful and XHTML Media Types, I see that they really should be sent with a Content-Type of application/xhtml+xml, but the former document states that IE 6 doesn’t support content delivered with that type.

And apparently we really shouldn’t send it as text/html. The reason given is that browsers are then forced into ‘quirks mode’ and presume it to be HTML4, complete with tag soup and subtly different interpretations.

Both these documents are quite old, so I was wonder what the current practice was? Do most browsers correctly handle application/xhtml+xml? Or do modern browsers accept text/html might not be quirky HTML 4 and make a more informed decision as to whether to treat it in quirks mode, or standards-compliance mode?

I am sending out validated XHTML 1.1, for the purposes of this query, so some of the arguments in the former paper (about the code not actually being valid XHTML) don’t hold water.

11 thoughts on “Delivering XHTML 1 documents over HTTP

  1. I have discovered that if Firefox loads a xHTML file in xHTML mode it makes a lot of problems with content inserting/mangling with JavaScript. For example Flickr Badge and Google AdSence do not work in xHTML mode.

  2. The bottom line is that :

    • Send text/html if you serve HTML
    • Send application/xhtml+xml if you serve XHTML

    Now if your pages are valid XHTML and do not host any other XML formats (such as XForms or SVG) then you may use text/html. Now if you do, the UA will not handle your document as XML but as HTML which is not so much a problem when you serve XHTML which only matches what HTML4 offers.

    If you want to serve your XHTML as application/xhtml+xml, you can be sure you’ll loose every users browsing via Internet Explorer because IE does not have any XML (hence XHTML) engine. Basically, IE does not understand the tiniest bit of XML. Nada. Interestingly, the IE team said they would not provide one in IE 7 either because they’d rather take their time and do it well rather than do it badly (considering the fact XHTML appeared 5 years ago I can’t imagine how long it’ll take them…).

    What you could do so is to check the Accept header in the incoming HTTP request and see whether or not the UA supports application/xhtml+xml and then send XHTML content, otherwise simply send HTML as text/html.

    But this is quite annoying because it requires twice more work on the developer side which we should not have anymore. The problem is that as long as Microsoft holds such a big portion of the browser market, there is no chance for the situation to get better for you as a developer. This is the same old problem as their lack of support of CSS 2, XForms, SVG, etc.

    Remember also that when the UA works with an XML engine, that engine also applies to the CSS you include and any Javascript processing, so if you do have valid XHTML but you send it as text/html, you may not get the expected result once you switch to application/xhtml+xml.

  3. Thanks for all your responses. It sounds like there’s not really a simple answer in practice, and that the easiest solution is to stick to the subset of XHTML 1.0 which is compatible with HTML, then serve it as text/html.

  4. Just to clarify what other poster’s have said:

    This is nothing to with quirk’s mode. That is simply using the DOCTYPE to choose which type of HTML rendering to use.

    XHTML 1.1 MUST be served as application/xhtml+xml to meet the specs. This will cause any version of IE to choke.

    XHTML 1.0 can be served at text/html but (I think) then will be rendered as HTML.

    So as you say you can stick to the subset of XHTML that is recognized by HTML renderers but then you aren’t gaining much. The specs forbid you from serving XHTML 1.1 as text/html…

  5. OK, so in summary, I have the following choices:

    • I do the right thing regarding all the standards, use the latest hoopy XHTML 1.1 code and lose my Internet Explorer audience completely. It’s tempting, but I might be shooting myself in the foot!
    • Stick to XHTML 1.0, and only the subset that is compatible with HTML 4, which seems pointless, since I might as well just use HTML 4 and get away with dodgy markup! :)
    • Do the Apache Accept mangling trick, so that at least capable browsers get the right thing; IE can make a better-effort guess by being served text/html.

    Hum te tum. Who’d do web development, eh?

  6. Kai, considering that the WHATWG spec says:

    “This specification can also be viewed as an extension to [XHTML1]. In particular, some of the features added in this module only apply to XHTML documents”

    I assume one should not abandon XHTML.

    Now the problem was not about XHTML Vs HTML but what media type to use in each case. Since application/xhtml+xml is NOT supported by IE, I guess that it is correct to say that current practice advise to keep on doing HTML 4.

  7. It’s all overblown and you’re wasting your time talking about it. What pretty much everyone does is use XHTML 1.0 Transitional or Strict and serve it as text/html. And that’s it. Now stop thinking about it and build sites!

    Something fun to try – visit meyerweb.com, zeldman.com, tantek.com and the like, and I’m sure no one bothers doing xhtml+xml sniffing. It’s just not worth it. But developing good XHTML coding habits is like using Ruby. It’s just the smart, pretty thing to do.

    I can’t imagine going back to unclosed tags, tags and tables for layout. (Shudders.)

  8. I use XHTML without problems application/xhtml xml and really it doesn’t matter that much. It’s a weblog, and the content is accessible also through RSS 1.0, if people using old IE versions want to access my content.