HTML, XHTML and MIME Types

On the previous page I noted that XHTML is not HTML. Although technically this is true, XHTML 1.0 is designed to work like HTML in existing browsers. The same elements and attributes are used in both, and the W3C states that XHTML 1.0 MAY be sent as text/html to legacy browsers. Even Hixie states (in Appendix B of his text document) that it’s OK as long as the proper MIME type (application/xhtml+xml) is served to conforming user agents (browsers), and styling and scripting are set up to work properly on all user agents. That’s exactly what I am doing now, and I guess that puts me into the realm of “advanced authors”.

(NOTE: At this writing, Ummamum’s Picture Place and Petitt’s Creations are written in XHTML 1.1, which should not be served as text/html. I plan to remedy this by switching the DOCTYPE to XHTML 1.0 Strict. At that time I will also provide limited styling for Netscape 4.)

The W3C’s HTML compatibility guidelines (cited above), under point C.9 (Character Encoding), refer to documents being “served as multiple media types”. It looks like they foresaw this as a possibility and deem it okay too. To answer my cappuccino analogy on the previous page, I am serving black coffee to Internet Explorer, then providing cream and sugar via JavaScript and CSS.

Scripting Issues and Redundant Code

Currently this site uses only scripts that work in both XML and HTML environments, with the exception of special scripts for Internet Explorer and Netscape 4. I tried the greeting script for a couple of days until I learned that it broke on better browsers. I may fix the script and return it to service at a later date. This is a work in progress.

As far as the redundant id and name attributes are concerned, I have been living with this for over two years already. Blame it on existing user agents like Netscape 4 and mobile devices that can’t find an element by its id. In a perfect world, I would write the entire site in XHTML 1.1, serve it only as application/xhtml+xml and link only to id attributes within pages. But if I did that today, 90% of you wouldn’t be able to read this.

The style sheet linking methods are still under consideration. Rightfully I should use both the ?xml-stylesheet processing instructions and the <link> tags. A style switcher script may be in the works. This too is a work in progress.

OK… But Why Bother At All?

I left the reason for my decision until last, because it isn’t forward compatibility any more. Who knows what the future holds? It isn’t to use the extensiblity of XML, nor to mix XML namespaces, like Jacques Distler has done. My reason is simpler: my site statistics show that 5% of my hits are coming from Netscape 6 or 7, Mozilla, Firebird or Phoenix (they are listed separately for some reason), and those browsers will send an HTTP-ACCEPT header to the server which indicates that they actually prefer the MIME type application/xhtml+xml over text/html. When I tried content negotiation on another server, Netscape 7 and Mozilla received an XHTML page as application/xhtml+xml. Why not give them what they want, and give the other browsers what they can handle?

My final word for now is this: do this only if you really know what you are doing. My journey has been a long and difficult one, and the work is still in progress. Most authors are advised to stick with HTML 4.01 until support for XHTML dramatically improves.