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
- Slop is the new name for unwanted AI-generated content - 8th May 2024
- Weeknotes: more datasette-secrets, plus a mystery video project - 7th May 2024
- Weeknotes: Llama 3, AI for Data Journalism, llm-evals and datasette-secrets - 23rd April 2024
- Options for accessing Llama 3 from the terminal using LLM - 22nd April 2024
- AI for Data Journalism: demonstrating what we can do with this stuff right now - 17th April 2024
- Three major LLM releases in 24 hours (plus weeknotes) - 10th April 2024
- Building files-to-prompt entirely using Claude 3 Opus - 8th April 2024
- Running OCR against PDFs and images directly in your browser - 30th March 2024
- llm cmd undo last git commit - a new plugin for LLM - 26th March 2024
- Building and testing C extensions for SQLite with ChatGPT Code Interpreter - 23rd March 2024