简体   繁体   English

如果在内容类型标题中发送字符集,仍然建议通过元标记在头标记内发送?

[英]If sending charset within content-type header, still advisable to send within head tag via meta tag?

I do not have the link anymore as it was a few months back, but there was a great and detailed article about setting the charset of the body being sent to the user-agent. 几个月前我没有这个链接,但是有一篇很棒的详细文章关于设置发送给用户代理的正文的字符集。

The gist of the article was that when possible, send it via the content-type header since the user-agents parser will know before the body begins being parsed that it is (for example) utf-8, etc. 文章的要点是,在可能的情况下,通过内容类型标头发送它,因为用户代理解析器在主体开始被解析之前就知道它是(例如)utf-8等。

Sending it via meta tag means it has to wait for said meta tag to be found, then return to the top of document and begin reparsing the document again. 通过元标记发送它意味着它必须等待找到所述元标记,然后返回到文档的顶部并再次开始重新分析文档。

So for quite a while now, we have been sending the charset via content-type header, like so (in PHP anyways): 所以很长一段时间以来,我们一直在通过content-type标头发送charset,就像这样(在PHP中):

header('Content-type: text/html; charset=utf-8');

All works great. 一切都很棒。 As far as we can see everything is as should be in all the commonly used user-agents. 据我们所知,所有常用的用户代理都应该如此。

My question is this, as a backup / fail-safe / just in case, should we still send the charset meta tag? 我的问题是,作为备份/故障安全/以防万一,我们还应该发送charset元标记吗? Will sending it again using the meta tag defeat the purpose of sending it via the content-type header? 是否会使用元标记再次发送它会失败通过内容类型标头发送它的目的?


edit: This is not the exact article, but re-iterates the point ( http://code.google.com/speed/page-speed/docs/rendering.html#SpecifyCharsetEarly ) that when possible, send charset via header. 编辑:这不是确切的文章,但重新迭代点( http://code.google.com/speed/page-speed/docs/rendering.html#SpecifyCharsetEarly ),如果可能,通过标头发送charset。

Yes, I always try to do this since it makes the document more portable. 是的,我总是尝试这样做,因为它使文档更便携。 Eg It will display the same way when viewing from a local file, as it does when delivered via a web server. 例如,当从本地文件查看时,它将以与通过Web服务器传送时相同的方式显示。

my question is this, as a backup / failsafe / just incase, should we still send the charset meta tag? 我的问题是,作为备份/故障保护/只是因为我们还应该发送charset元标记吗?

Yes, it is always good practice to provide a meta tag in your markup which specifies the encoding. 是的,在标记中提供指定编码的元标记始终是一种好习惯。 It should be the first tag after the <head> . 它应该是<head>之后的第一个标签。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM