Problems with XHTML content type.
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
- Weeknotes: Parquet in Datasette Lite, various talks, more LLM hacking - 4th June 2023
- It's infuriatingly hard to understand how closed models train on their input - 4th June 2023
- ChatGPT should include inline tips - 30th May 2023
- Lawyer cites fake cases invented by ChatGPT, judge is not amused - 27th May 2023
- llm, ttok and strip-tags - CLI tools for working with ChatGPT and other LLMs - 18th May 2023
- Delimiters won't save you from prompt injection - 11th May 2023
- Weeknotes: sqlite-utils 3.31, download-esm, Python in a sandbox - 10th May 2023
- Leaked Google document: "We Have No Moat, And Neither Does OpenAI" - 4th May 2023
- Midjourney 5.1 - 4th May 2023
- Prompt injection explained, with video, slides, and a transcript - 2nd May 2023