Ian Hickson wrote a piece awhile ago called Sending XHTML as text/html Considered Harmful. He introduces several main points against sending XHTML documents with a text/html MIME type, which, I believe, are wholly unconvincing. I’ll comment on or refute each of his points below.
<script> and <style> elements in XHTML sent as text/html have to be escaped using ridiculously complicated strings.
This is not an issue if one includes scripts and stylesheets as external resources from their own files. This helps caching, organization, and modularization of code and should be used in all production environments. In the very rare case that scripts or styles need to included on the XHTML page itself, two extra lines delimiting CDATA blocks are not “harmful” to any degree. Not Harmful
Documents sent as text/html are handled as tag soup by most UAs…Since most authors only check their documents using one or two UAs, rather than using a validator, this means that authors are not checking for validity, and thus most documents that claim to be XHTML on the web now are invalid.
Which means that they are handled in exactly the same manner as HTML 4.01 Strict and other HTML documents. Is there a harmful issue here? No. Whether or not documents validate is a completely separate issue from the MIME type as which they are sent. It is up to authors alone to worry about validating their documents with a validator. Not Harmful
If you ever switch your documents that claim to be XHTML from text/html to application/xhtml+xml, then you will in all likelyhood end up with a considerable number of XML errors, meaning your content won’t be readable by users.
That only applies if the document wasn’t valid in the first place, which, as we’ve seen, is a completely orthogonal issue. Not Harmful
If a user saves such an text/html document to disk and later reopens it locally, triggering the content type sniffing code since filesystems typically do not include file type information, the document could be reopened as XML, potentially resulting in validation errors, parsing differences, or styling differences. (The same differences as if you start sending the file with an XML MIME type.)
Again, this is author-dependent and has nothing to do with the initial decision to send an XHTML document as text/html. If one writes valid XHTML in the first place, none of these problems will arise. Not Harmful
The only real advantage to using XHTML rather than HTML4 is that it is then possible to use XML tools with it. However, if tools are being used, then the same tools might as well produce HTML4 for you. Alternatively, the tools could take SGML as input instead of XML.
I disagree here and this difference might be telling. I believe the biggest advantages to XHTML are its readability, uniformity, well-formedness as it pertains to authoring, and the consistency of the rendered DOM (which is also a result of any well-formed HTML document). Either way, just because a certain advantage of XHTML can be duplicated via other older methods doesn’t mean that XHTML is harmful in itself. Not Harmful
HTML 4.01 contains everything that XHTML 1.0 contains, so there is little reason to use XHTML in the real world. It appears the main reason is simply “jumping on the bandwagon” of using the latest and (perceived) greatest thing.
I disagree for the reasons stated in the previous point. Some authors may use XHTML due to some trendy force, but that doesn’t make the use of XHTML harmful. Indeed, I’ve refuted the main arguments against XHTML’s harmfulness and provided several reasons for its usefulness. Not Harmful
Then he goes on to talk about how XHTML documents aren’t compatible with HTML documents and lists several points. Needless to say, none of these points about incompatibility with HTML means incompatibility with current browsers, which all handle XHTML sent as text/html as expected.
The “/>” empty tag syntax actually has totally different meaning in HTML4.
That’s all well and good, but all modern browsers deal with the empty tag as a single tag without using HTML’s different meaning. Not Harmful
Script and style elements cannot have their contents hidden from legacy UAs.
Again, this is not a problem when one includes these resources from external files. Not Harmful
The “xmlns” attribute is invalid HTML4. The XHTML DOCTYPEs are not valid HTML4 DOCTYPEs.
These have nothing to do with the harmfulness of XHTML in itself. Not Harmful
He goes on to analyze why XHTML sent as text/html can’t be interpreted as XML, but that again is orthogonal to the main benefits of XHTML in my opinion. In conclusion, he sums up:
There are few advantages to using XHTML if you are sending the content as text/html, and many disadvantages.
There are not nearly as many disadvantages (if any) to sending XHTML as text/html as he claims and the advantages I mentioned above make it well worth using in my humble opinion. There are some subtle footnotes and parentheticals indicating that the harmfulness only applies to authors that don’t know the pitfalls of this practice, but much like the “Do not eat” label on the little packets of silica gel, Ian’s advisory seems to be common sense and not worth mentioning to any author who actually knows what XHTML is and how to write it.
December 21, 2005
Let me know what you think by emailing me.