html – 如何修复“错误:在前512个字节之后找到的元元素的charset属性.

前端之家收集整理的这篇文章主要介绍了html – 如何修复“错误:在前512个字节之后找到的元元素的charset属性.前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我的网站在验证时收到此错误.
Error: A charset attribute on a Meta element found after the first 512 bytes.

这里是我怀疑的代码,导致这个问题:

<!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">

解决方法

将元条目移动到所有其他条目之上,例如:
<!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>

你的问题在于你违反W3C HTML5 recommendation

The element containing the character encoding declaration must be serialized completely within the first 1024 bytes of the document.

无论您使用的测试有些过时,限制过去都是512字节,但是在2012年12月更新了(最近).

那些相当大块的脚本标签正在将字符集规范推送到测试工具的512字节范围之外.即使您使用以后的测试工具将更改识别为1024字节,仍可能是一个问题.将元标记放在前面的建议应该可以解决两种情况.

原文链接:https://www.f2er.com/html/229580.html

猜你在找的HTML相关文章