application/xhtml+xml
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
will crywon’t care.
Guess who doesn’t support true XHTML? Yes, yes. Commence grumbling. Internet Explorer will scream and run at the mere sight ofapplication/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 toodenseunenlightened to 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.
See also
Fix your site with the right DOCTYPE
Mozilla Docs on application/xhtml+xml
W3C Recs on XHTML
Anne on MIME types matter, DOCTYPEs don’t
The perils of using XHTML properly
8:11 am
Ah, so that’s the reason. I encountered some XML parsing error messages when I tried to visit your blog yesterday. I wanted to tell you, but I was “busy”…
10:12 am
Wow, so much I never knew before…
I learn a lot of things from you Seth :wub:
Oh, and I like the bit about IE totally dying on people that try to view application/xhtml+xml sites
Mmm, annoying popups for IE users, nice
4:11 pm
Great job Seth! Now for the important question
how?