Problems with XHTML content type.
30th May 2007
My answer to Problems with XHTML content type. on Ask MetaFilter
The first question you should be asking is why you need XHTML—if you don’t have a specific reason (the need for XML parsers to be able to consume your pages) you’re much better off with HTML 4.01 for now, and HTML 5 in probably a year or so.
As for serving up XHTML, you need to check the browser’s HTTP_ACCEPT header to decide whether or not to serve it (IE, including IE 7, can’t handle it at all and will offer to download it).
< ?phpbr> if ( stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") ) { header("Content-type: application/xhtml+xml"); } else { header("Content-type: text/html"); } ?>< />Be warned: there are a TON of gotchas involved in serving using the application/xhtml+xml content type, especially relating to JavaScript. This article from 2003 is still very relevant.
Then at 15:07:
Forgot to mention: the best reason to use XHTML is if you want to embed SVG or MathML in your pages. Again, that trick won’t work in any existing version of Internet Explorer.
Generally though it’s best avoided. I served my personal site in XHTML with the correct content type for several years; it was a nuisance. The XML error model is fundamentally unsuited to the Web.
One of the reasons HTML 5 is so interesting is that it attempts to specify an error model that is as close as possible to the way actual browsers work today.
More recent articles
- Prompt injection explained, November 2023 edition - 27th November 2023
- I'm on the Newsroom Robots podcast, with thoughts on the OpenAI board - 25th November 2023
- Weeknotes: DevDay, GitHub Universe, OpenAI chaos - 22nd November 2023
- Deciphering clues in a news article to understand how it was reported - 22nd November 2023
- Exploring GPTs: ChatGPT in a trench coat? - 15th November 2023
- Financial sustainability for open source projects at GitHub Universe - 10th November 2023
- ospeak: a CLI tool for speaking text in the terminal via OpenAI - 7th November 2023
- DALL-E 3, GPT4All, PMTiles, sqlite-migrate, datasette-edit-schema - 30th October 2023
- Now add a walrus: Prompt engineering in DALL-E 3 - 26th October 2023
- Execute Jina embeddings with a CLI using llm-embed-jina - 26th October 2023