I’m now serving my website with a MIME type of
application/xhtml+xml, rather than
text/html as it used to be (and as 99% of websites are). What does this mean, you ask? Anything important?
Well, not really for you. Mostly for me. But those reasons are the same ones that mean you should be implementing
application/xhtml+xml on YOUR site, too.
- XHTML served as
text/htmlis tag soup.
Yes kids, it’s true. XHTML does not exist in HTML, so no matter what DOCTYPE you’re using, you’re still getting nothing but HTML. There is no such thing as <br /> in HTML. All one-sided tags close themselves. Many other examples as well. So why is this important? Because browsers are happiest about rendering XHTML when you tell them it’s XHTML. This forced rendering has as its side effect…
- Write good code or die.
If you have just one bad tag or misplaced identifier, your site will die. This is good. It forces you to write good code and not get sloppy. You’ll notice sometimes my site dies because I need to fix IdioQuote to output characters like & and > in their encoded forms. Being forced to code correctly means your site will always be valid.
- You can create your own selectors easily.
With a true XHTML page, it’s easy to create custom tags that you can use in special ways. Check out this excellent article on creating your own XML namespace. Want to mark up PHP code with syntax coloring? Yes please.
- IE users
Guess who doesn’t support true XHTML? Yes, yes. Commence grumbling. Internet Explorer will scream and run at the mere sight of
application/xhtml+xml, so you must use PHP to sniff for it and deliver good old HTML 4.01 Strict to that evil browser. Not so hard… but they’ll miss all the eye candy. Chances are though, if they’re using Internet Explorer, they’re too
denseto notice that there was any hope of eye candy to begin with. (Note to self, get an annoying popup for IE users soon!
But in the end, the benefits are almost entirely for me, the developer. And they could be yours too… if you learn to use MIME types.