有没有比 w3c 验证器更好的 html 标准验证方法?

Is there a better approach to html standards validation than w3c validator?

诚然,这是一个非常普遍的问题,但我想知道 w3c 验证是否被认为是 html 验证的最佳实践,或者是否有更好的方法来确保符合当代标准的标记。

当我注意到 an MDN page 上的重复 ID 时出现了这个问题(我认为这个网站对其编码实践非常严格)。它似乎是他们如何生成页面部分的产物。

好奇,我在 w3c 验证器上验证了页面代码,有各种 "errors" 表明 MDN 只是忽略了某个属性或值无效。通常,这些与 rel 属性看似恰当的使用有关。

我想知道有效的语义标记标准是否更重要,或者是否有一种比依赖 w3c 验证更理想的代码验证和标准化新方法。

这里是当前W3C HTML Checker(验证者)的维护者。我认为了解当前 HTML 检查器的预期目的很重要,这与旧版 W3C 标记验证器的目的不同。

检查器的目的记录在 https://validator.w3.org/nu/about.html#why-validate:

The core reason to run your HTML documents through a conformance checker is simple: To catch unintended mistakes—mistakes you might have otherwise missed—so that you can fix them.

Beyond that, some document-conformance requirements (validity rules) in the HTML spec are there to help you and the users of your documents avoid certain kinds of potential problems.

There are some markup cases defined as errors because they are potential problems for accessibility, usability, interoperability, security, or maintainability—or because they can result in poor performance, or that might cause your scripts to fail in ways that are hard to troubleshoot. Along with those, some markup cases are defined as errors because they can cause you to run into potential problems in HTML parsing and error-handling behavior—so that, say, you’d end up with some unintuitive, unexpected result in the DOM

Validating your documents alerts you to those potential problems.

就您关于 "are better approaches to ensure contemporary standards-compliant markup" 的问题而言,答案是这不是非此即彼的事情;有多种方法,W3C HTML Checker 只是其中之一,它的目标不是确定任何事情的唯一方法,而是帮助您发现错误,否则您可能会错过这些错误给您的用户带来意想不到的问题。


就针对特定设备问题或浏览器实现问题发出警报的方法而言,我们没有为此提供良好的自动检查工具,但有几件事情非常有用:

  • https://caniuse.com/ — 有关不同浏览器、这些浏览器的不同版本以及移动设备浏览器版本的特定网络运行时功能支持级别的详细信息对比桌面

  • https://wptdashboard.appspot.com/ — 数十个 web 运行时所有主要浏览器引擎的当前测试结果 features/specs ;如果 https://caniuse.com/ 没有关于特定功能的信息,您可以查看此仪表板并浏览到具有该功能测试的目录,然后查看浏览器是否通过了该功能的测试

但就我们实际拥有的用于检查其他内容的良好自动化工具而言,这里有两个:

我最近遇到了上面提到的问题W3C HTML Checker。我尊重此验证器作者所做的大量工作,但它不允许我以任何方式 标记 <script type="text/vbscript" src="file.vbs">。据说将 type 值更改为 空字符串、JavaScript MIME 类型或模块 ,这使我的页面无用。

我知道现在很少使用 VBScript 语言,它只是一个测试页,但让我与您分享不那么棘手的替代方案,与第一个一样好 HTML 错误检查。

当前 JsonFormatter(验证器)的维护者是 here