4 ms·
> Do MIME types in HTTP headers affect how browsers render content? They absolutely do matter. To make an extreme point, if that page was served as text/plain,
by nayuki 4y ago
> Do MIME types in HTTP headers affect how browsers render content?
They absolutely do matter. To make an extreme point, if that page was served as text/plain, then the browser would show the literal XHTML source code on screen. Auto-sniffing the type based on the content is a big no-no where we learned lessons about vulnerabilities like ~20 years ago.
The text/html and application/xhtml+xml modes have many subtly different behaviors. XHTML supports things like <![CDATA[ ... ]]> and requires namespaces like <html xmlns="http://www.w3.org/1999/xhtml http://www.w3.org/1999/xhtml">, <svg xmlns="http://www.w3.org/2000/svg http://www.w3.org/2000/svg">. XHTML requires well-formed elements, so no <b><i></b></i>. XHTML treats <div/> as identical to <div></div>, whereas HTML5 interprets it as just <div> with no closing.
Here is my guide on XHTML, and the page itself and entire website is served as application/xhtml+xml: https://www.nayuki.io/page/practical-guide-to-xhtml https://www.nayuki.io/page/practical-guide-to-xhtml
- TRiG_Ireland 4y agoSmall error in that sample script: let elem = document.createElement("img"); console.log(el.tagName); // el is not defined