请问有人能帮我理解html/xhtml页面的文档类型和内容类型之间的区别吗?
我知道文档类型用于浏览器确定选择哪种模式(标准/怪异)并遵循哪种文档类型方案被使用?
- 那么我们在meta标签中指定的内容类型是什么?
- 它与文档类型有何关系/差异?
- 这个内容类型在页面渲染时有什么重要性?
- 指定内容类型是否有助于浏览器性能?
- 此外,有哪些内容类型?
请问有人能帮我理解html/xhtml页面的文档类型和内容类型之间的区别吗?
我知道文档类型用于浏览器确定选择哪种模式(标准/怪异)并遵循哪种文档类型方案被使用?
Then what is the content type we specify in meta tags?
For HTML, it is text/html
. This is the default for most Web pages.
For XHTML, it is (usually) application/xhtml+xml
.
There's also a character encoding, typically charset=utf-8
.
This usually doesn't matter, though; in most cases the content type will be sent in the Content-Type HTTP header by the server. When a browser picks up the header it will ignore the meta tag.
In HTML5 only the charset is specified:
<meta charset="UTF-8">
Does it have any relation/difference to document type?
No.
How is this content type significant when comes to page rendering?
The same markup, assuming it is well-formed XML, can produce different DOMs in certain cases when it is served as application/xhtml+xml
as opposed to text/html
. These differences are minor, but may have different effects on page rendering.
You can write markup that will produce identical DOMs whether served as HTML or XHTML. This is known as polyglot markup.
Does specifying content type help the browser in terms of performance?
No.
Also, what all content types are there?
Concerning HTML/XHTML there are only the two I've mentioned. All the other content types (or MIME types) are irrelevant here.