已知:content-type 指代 HTML 协议的 payload 的类型与编码, 当 payload 是 html document 时,假设 content-type 中 charset 是 A ,
那么浏览器会以 A 来解码这个 html document 吗?当浏览器解析 document 匹配到 meta 标签时,如果 meta 标签里的 charset 是 B ,浏览器接下来来会如何解析这个 document ?会换用 B 去解码接下来的字符吗? meta charset 这种设计的应用场景是哪里呢?
举报· 83 次点击
登录 注册 站外分享
4 条回复  
JinTianYi456 小成 2023-8-14 20:03:37
Do both. The header takes precedence, but if the HTML page is accessed locally, there are no HTTP-headers, so you want to have <meta charset="..."> as a safety mechanism.
i8k 小成 2023-8-14 20:02:25
In HTML5, they are equivalent. Use the shorter one, as it is easier to remember and type. Browser support is fine since it was designed for backwards compatibility.

https://stackoferflow.com/questions/4696499/meta-charset-utf-8-vs-meta-http-equiv-content-type
rrfeng 小成 2023-8-14 19:23:39
content-type 指代 HTML 协议的 payload 的类型与编码
-----
content-type 指代 HTTP 协议的 payload 的类型与编码
返回顶部