Serving up application/xhtml+xml
Most web pages written in XHTML are not served to the browser as XHTML, but as HTML. If they were served as XHTML, (according to the W3C specification) a single mistake in coding would prevent the entire page from displaying.
You see, contrary to popular belief, on the web, extensions don't necessarily mean a thing. It's a document's Content-type (also called a MIME type) that determines what type of file we have, and how it should be handled. The file extension is merely the only method a user has to designate a file as this type or that, but the server administrator can alter the server settings to recognize that particular extension to whatever content-type he prefers. He can even have a file with a .chickenbutt extension and make it run PHP script.
What does this all mean?
What this means in essence is that future versions of XHTML will require that your code be valid. And future browsers will have built-in validation mechanisms, which determine if your code is up to spec or not. Even highly reputable organizations will finally even have to conform if they wish for their pages to render.
What you can do in the meantime though, is use server-side technology to change the MIME type of your pages for XHTML-compliant browsers (such as Firefox).
Here is a script you can use to make the server send your XHTML code as XHTML if the clients browser supports it, if not, it sends it as HTML.
Using PHP
if (stristr($_SERVER['HTTP_ACCEPT'], "application/xhtml+xml"))
{
header("Content-Type: application/xhtml+xml; charset=iso-8859-1");
}
else
{
header("Content-Type: text/html; charset=iso-8859-1");
}
Using ASP
If InStr(Request.ServerVariables("HTTP_ACCEPT"), "application/xhtml+xml") > 0
Then
Response.ContentType = "application/xhtml+xml"
Else
Response.ContentType = "text/html"
End If
If you want to make the transition to XHTML, you must first understand the meaning of "well-formed" (in other words, sticking to the very precise rules of XML). If you fail to do so, you will simply be writing web pages that will fail miserably in browsers, if, and when, they start supporting XHTML in the manner the W3C intended.
Regardless of whether you use HTML or XHTML, make sure your web pages validate. Separate content from presentation by using CSS. That way, they will be easier to maintain, less likely to fail in current or future browsers, and probably load a lot faster.
Feb 05, 2007
Comments
This article hasn't been commented yet.

Write a comment
* = required field