在< head&gt中,首先出现:< meta>或< title&gt ;? [英] In <head>, which comes first: <meta> or <title>?

查看:107
本文介绍了在< head&gt中,首先出现:< meta>或< title&gt ;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在读这篇文章:


这个[meta]标签应该是
HEAD部分中的第一个,因为服务器将
处理上面的文本作为ASCII,
没有特定的格式


http://www.xul.fr/en/html5/html.php



标准指定订单?



两种订单都有缺点吗?

正如所有其他答案已经表明的那样,通常并不重要。以下是关于什么时候重要以及为什么的更多信息。



首先,当您询问标准时,您可能想知道您引用的文本来自W3C对HTML 4的建议:

http://www.w3.org/TR/html4/charset.html#h-5.2.2



HTML 5草案标准中的类似讨论:

http://dev.w3.org/html5/markup/syntax.html#encoding-declaration



底层问题在于浏览器必须使用一些字符集编码来开始处理从服务器接收到的文档。那么,如果从一个字符集开始,然后< meta> 标签告诉它使用其他东西,会发生什么?答案是,它取决于...



服务器应该指定 Content-Type 字段的HTTP响应头。如果确实如此,浏览器应该使用该字符集并忽略可能在被服务的文档中的< meta> 标签中指示的任何字符集。



不幸的是,许多服务器不提供这些信息。在这种情况下,浏览器必须假设一些事情开始。东西必须是ASCII兼容的,这意味着它与ASCII范围内的任何字符都符合ASCII。如果文档在< meta> 标签中指定了字符集,浏览器将开始使用该字符集。因此,如果您的标题在此之前出现,它已被解释为ASCII,这可能是错误的,具体取决于标题内容。



总结:if服务器没有指定编码,并且标题的编码方式不是ASCII,那么您需要将< meta> 标签指定为<$ c $首先是c> charset 。否则,这并不重要。所以,为了安全起见,首先为字符集放置< meta> 标签是有意义的。

In head, which comes first: meta or title?

I was reading this:

This [meta] tag should be the first in the HEAD section, because the server will process the text above as ASCII with no specific format that it only known once the tag is analyzed.

http://www.xul.fr/en/html5/html.php

Does the standard specify the order?

Are there disadvantages in either order?

解决方案

As all of the other answers have already indicated, it usually doesn't matter. Here's a bit more about when it matters and why.

First of all, since you asked about standards, you might like to know that the text you are quoting comes from the W3C recommendations for HTML 4:

http://www.w3.org/TR/html4/charset.html#h-5.2.2

There is a similar discussion in the HTML 5 draft standard:

http://dev.w3.org/html5/markup/syntax.html#encoding-declaration

The underlying issue here is that the browser has to use some character set encoding to start processing the document it receives from the server. So, what happens if starts with one character set and then the <meta> tag tells it to use something else? The answer is, it depends...

The server should specify the character set in the Content-Type field of the HTTP response header. If it does, the browser is supposed to use that character set and ignore any character set that may be indicated in a <meta> tag in the document being served.

Unfortunately, many servers don't provide this information. In that case, the browser has to assume something to get started. The something has to be "ASCII-compatible", meaning that it agrees with ASCII for any characters in the ASCII range. If the document specifies the character set in a <meta> tag, the browser will start using that character set. So, if your title came before that, it has already been interpreted as ASCII, which could be wrong, depending on what was in the title.

To sum up: if the server does not specify the encoding, and the title is encoded in something other than ASCII, then you need to put the <meta> tag that specifies the charset first. Otherwise, it doesn't matter. So, to be safe, it makes sense to put the <meta> tag for the character set first.

这篇关于在&lt; head&gt中,首先出现:&lt; meta&gt;或&lt; title&gt ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆