Html 如何修复“错误:在前 512 个字节之后找到的元元素上的字符集属性。”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18007771/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I fix "Error: A charset attribute on a meta element found after the first 512 bytes."
提问by Anon
I am getting this error for my site in validation.
我的网站在验证中收到此错误。
Error: A charset attribute on a meta element found after the first 512 bytes.
and here is code causing this problem:
这是导致此问题的代码:
<!DOCTYPE html>
<html class="not-ie no-js" lang="en-US" prefix="og: http://ogp.me/ns#">
<head>
<link rel="stylesheet" type="text/css" href="http://mywebsite.com.au/wp-content/cache/minify/000000/TY3RDsIgDEV_SFb5pAqVgLDWFTb79y6bWXw6ybk3OR4KdcHwgsZxVFLYckzUL97uoN0q7QyqUN6DFpueOAd78Gdqef4ta47EruifwhEzS0WjZfWH97CJSw1FcjdHqOYSc6rkdqdnaU_LdRHW7k79BQ.css" media="all" />
<script type="text/javascript" src="http://mywebsite.com.au/wp-content/cache/minify/000000/hY7RDsIgDEV_aFCXmCzxb5DVDQSKtDj164W5dx977rltV5F8ATDevPRCtAQ02bG2FHcGwV0Z_KNiecOoJz0eg44uac_DCTxDpBlLcp-ibWWh-KNPNyMpz10dztBWRkyiCuaw14exsSTGirpRiWoCl2yoM3JvH2d68l9mW1wWbpJHycbe-0s1tHDLS6GVvg.js"></script>
<script type="text/javascript" src="http://mywebsite.com.au/wp-content/cache/minify/000000/M9YvzdTPKixNLarUK83UK89MSU8t0cvNzAMA.js"></script>
<script type="text/javascript" src="http://mywebsite.com.au/wp-content/cache/minify/000000/ZY5BDsIwDAQ_RNIWxEt4gUkMuKRxsJPS8HpacahQLnuYnZW270btFAO6TDN9xED0BpcsYH6URe1E8dBvoqAmjn4H46ugVIugFO9msKemukF09cqLTeCef42rLqCFEJqNTiD5krcI5FEagZQzJ2z46EC4rMf3BoonTgEqyjw0g8zFPS5vSrieP9rzLriimacv.js"></script>
<meta charset="UTF-8">
回答by paxdiablo
Move the meta
entry to above all those other entries, such as:
将meta
条目移至所有其他条目之上,例如:
<!DOCTYPE html>
<html class="not-ie no-js" lang="en-US" prefix="og: http://ogp.me/ns#">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="http://mywebsite.com.au/wp-content/cache/minify/000000/TY3RDsIgDEV_SFb5pAqVgLDWFTb79y6bWXw6ybk3OR4KdcHwgsZxVFLYckzUL97uoN0q7QyqUN6DFpueOAd78Gdqef4ta47EruifwhEzS0WjZfWH97CJSw1FcjdHqOYSc6rkdqdnaU_LdRHW7k79BQ.css" media="all" />
<script type="text/javascript" src="http://mywebsite.com.au/wp-content/cache/minify/000000/hY7RDsIgDEV_aFCXmCzxb5DVDQSKtDj164W5dx977rltV5F8ATDevPRCtAQ02bG2FHcGwV0Z_KNiecOoJz0eg44uac_DCTxDpBlLcp-ibWWh-KNPNyMpz10dztBWRkyiCuaw14exsSTGirpRiWoCl2yoM3JvH2d68l9mW1wWbpJHycbe-0s1tHDLS6GVvg.js"></script>
<script type="text/javascript" src="http://mywebsite.com.au/wp-content/cache/minify/000000/M9YvzdTPKixNLarUK83UK89MSU8t0cvNzAMA.js"></script>
<script type="text/javascript" src="http://mywebsite.com.au/wp-content/cache/minify/000000/ZY5BDsIwDAQ_RNIWxEt4gUkMuKRxsJPS8HpacahQLnuYnZW270btFAO6TDN9xED0BpcsYH6URe1E8dBvoqAmjn4H46ugVIugFO9msKemukF09cqLTeCef42rLqCFEJqNTiD5krcI5FEagZQzJ2z46EC4rMf3BoonTgEqyjw0g8zFPS5vSrieP9rzLriimacv.js"></script>
Your problem lies with your violations of the W3C HTML5 recommendation:
您的问题在于您违反了W3C HTML5 建议:
The element containing the character encoding declaration must be serialized completely within the first 1024 bytes of the document.
包含字符编码声明的元素必须在文档的前 1024 个字节内完全序列化。
Whatever test you're using is somewhat out of date, the limit used to be 512 bytes but was changed (at the latest) December 2012.
无论您使用什么测试都有些过时,限制曾经是 512 字节,但已更改(最迟)2012 年 12 月。
Those rather chunky script
tags are pushing the character set specification well outside the 512-byte range of your test tool. Even if you use a later test tool that recognises the change to 1024 bytes, it may still be a problem. The advice to put the meta
tag up front should fix either case.
那些相当大的script
标签将字符集规范推到了测试工具的 512 字节范围之外。即使您使用稍后的测试工具识别到 1024 字节的更改,它可能仍然是一个问题。将meta
标签放在前面的建议应该可以解决任何一种情况。
回答by Hugo Rush
Just put
就放
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
like full sentence instead of only writing
喜欢完整的句子而不是只写
<meta charset="UTF-8">
it works fine for me.
这对我来说可以。
回答by p e p
Try putting the meta tag as the first thing inside head
尝试将元标记作为 head 中的第一件事
回答by Martin
This error also occurs if you have the tag appearing more than once in the <head>
code on the page. Check you have not inadvertently written this twice.
如果您<head>
在页面上的代码中多次出现该标记,也会发生此错误。检查你没有无意中写了两次。