HTML文档的字符编码声明未找到。

8

我在Firefox的web控制台(js选项卡)中随机遇到了这个问题。

它只是突然出现了,而且我无法将其与我所做的任何更改联系起来。

完整的错误信息如下:

The page was reloaded, because the character encoding declaration of the HTML document was not found when prescanning the first 1024 bytes of the file. The encoding declaration needs to be moved to be within the first 1024 bytes of the file.

或者是这个:
The character encoding declaration of the HTML document was not found when prescanning the first 1024 bytes of the file. When viewed in a differently-configured browser, this page will reload automatically. The encoding declaration needs to be moved to be within the first 1024 bytes of the file.

这个问题指向了这一行代码:
<meta http-equiv="Content-Type" content="text/html" charset="UTF-8" />

对我来说,那个元标签没问题吗?帮帮我,因为我认为它会与其他事情冲突并引起问题。
克雷格
2个回答

13

字符集是内容类型的参数,而不是单独的属性:

<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />

或者,如果您想使用HTML 5风格:

<meta charset="utf-8">

你还应该注意错误信息:

在预测文件前1024字节时未找到

您可能需要将 meta 标签移到文档的顶部。理想情况下,它应该是 <head> 中的第一个标签。


1
我已经将包含每个页面要包含的内容的init文件移动到了meta上面,我猜这将meta从head中推出了范围。不过现在已经解决了,谢谢 :) - Lovelock

0

我在Firefox中遇到了这个错误信息。当我在我的nginx设置中使用“pagespeed DisableFilters add_head;”时,它就消失了。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接