XHTML and Mime Types


The Zen Garden launched as an XHTML 1.1 document. After all, the markup passed XHTML 1.1 validation, so why not use that instead of the older XHTML 1.0 Strict?

As it turns out, there's more to XHTML than just closing tags properly. Even if you validate your XHTML, and it does turn out that it's completely valid, it's not technically XHTML unless you're serving it up with the correct MIME type.

MIME is a standard for describing information, and the only reason you need to know about it is because the correct MIME type for XHTML is application/xhtml+xml. You can use the far more common text/html, which is also the default for HTML, but only if you're using XHTML 1.0 Transitional or if your XHTML 1.0 Strict is meant to be backward-compatible. You may never serve XHTML 1.1 as text/html; it's always supposed to be served with an XML MIME type.

Serving XML documents with the proper MIME type involves programmatically hooking into the HTTP headers your server sends and altering those, potentially through .htaccess or httpd.conf files. If you have no idea what we're talking about, it's not your fault. This can be really low-level, technical stuff for the uninitiated, as it falls in the realm of server administration.

But once you've figured out how to serve the correct MIME type, the problems with using it are far from over. Only the most recent browsers support application/xhtml+xml, so a switching method is necessary to selectively serve it to them, while serving a more compatible MIME type to older browsers.

Note

You can find a pair of articles detailing the MIME type issue at greater length at the Web Standards Project (www.webstandards.org/learn/askw3c/sep2003.html) and XML.com (www.xml.com/pub/a/2003/03/19/dive-into-xml.html).


Further, once you turn on the proper MIME type, you trigger XML-parsing in your browser. XML has a rule that says if an error has occurredfor example, a missing </p> tagthe data must stop being parsed and return an error message. You won't even get partial rendering in your browser; you simply won't see your Web page (FIGURE 16). An XML document must be well formed, and that's thatthere's no room for error.

Figure 16. The result of XML that isn't well formed.


Is XHTML really worth all this? The whole point of XHTML was to reformulate HTML as an application of XML, after all. So it seems odd to some that you would bother using XHTML without serving it as genuine XML. The benefits of serving it this way are almost nonexistent, but pedantically speaking it's necessary if you're going to call it XHTML. If you choose not to worry about this, you're not alone. Many of the world's leading Web designers use XHTML and the text/html MIME type without a moment's pause. You're certainly in good company; just make sure to avoid using XHTML 1.1, and use only the 1.0 variants. You might also choose to avoid the issue completely and simply stick with HTML 4.01, which is properly served as the easier text/html and may be written according to similar rules as those for XHTML.

The lesson learned is that XHTML is simple on the surface, but once you start digging into the real implications, there's a whole tangled mess of issues awaiting you.



    The Zen of CSS Design(c) Visual Enlightenment for the Web
    The Zen of CSS Design(c) Visual Enlightenment for the Web
    ISBN: N/A
    EAN: N/A
    Year: 2005
    Pages: 117

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net