Which MIME type should I use to serve XHTML5 to IE

2019-04-10 23:12发布

I want to use XHTML5 but apparently they two browsers don't accept the application/xhtml+xml MIME type. I read that they will accept text/xml (or application/xml not sure) but it is kind of hackish. So I was wondering if I should just serve HTML5 to IE7 and IE8?

Please don't go on talking about XHTML vs HTML advantages. I know.

3条回答
我想做一个坏孩纸
2楼-- · 2019-04-11 00:00

My split-the-difference recommendation:

  • On the server, use an XML-based processing pipeline.
  • But right before you emit the HTTP response body, convert to the HTML5 serialization.
    • That means <!doctype html> and no <?xml ...?> nor xmlns directives.
  • Serve your pages with Content-Type: text/html; charset=utf-8. (Change the value of the charset parameter if you must, but PUT ONE IN, or you risk UTF-7 trickery.)
  • Don't try to condition any of this on the user-agent.

You get the benefits of XML strictness on the server -- you'll notice if you're generating invalid markup, and it makes it much harder to get quoting wrong -- but you don't have to deal with figuring out which clients will actually honor XML mime types.

Note that you can directly embed SVG and MathML in HTML5 even when you're using the HTML5 serialization (the <svg> and <math> elements are magic).

查看更多
Ridiculous、
3楼-- · 2019-04-11 00:07

XHTML 5 is not a standard. XHTML 2 does prescribe a new doctype, though XHTML 2 is not supported by any modern browsers (as it is largely unfinished).

HTML5Doctor recommends that if targeting an "XHTML5" approach, simply use the HTML5 doctype, which makes sense. The HTML5 doctype is compatible with IE7/8.

http://html5doctor.com/html-5-xml-xhtml-5/

Remember, to use HTML5 (properly) in IE <9, you need to include the HTML 5 shiv.

http://ejohn.org/blog/html5-shiv/

Also, in terms of a MIME type for XHTML5, you MUST serve the content with application/xhtml+xml or application/xml, which older version of IE will NOT support. Thus, if you're trying to take a purist approach, you CANNOT have IE 6/7 support.

查看更多
beautiful°
4楼-- · 2019-04-11 00:11

It doesn't really matter so long as you:

  • Use one which triggers Standards Mode
    • HTML 5
    • XHTML 1.0
    • HTML 4.01 Strict ** HTML 4.01 Transitional (but not the short form that omits the URI)
  • Serve code that conforms to the DTD (it makes QA testing that much easier)
    • … or spec if you use HTML 5 (since there is no DTD)
  • Follow the Compatibility Guidelines if you serve up XHTML

Using the same Doctype throughout is generally a good idea.

Serving up as application/xhtml+xml to some browsers and the same content as text/html to other browsers is generally a waste of time and effort.

查看更多
登录 后发表回答