Chrome 76 本机延迟加载属性 returns w3c 中的错误

Chrome 76 native lazy loading attribute returns error in w3c

我刚刚在一些图像中实现了 chrome 76 的新原生延迟加载。 它只是简单地将属性 loading="lazy" 添加到 images.

例如:

<img src="#url" width="380" height="285" alt="altexample" loading="lazy">

但令我惊讶的是 w3c 返回了以下错误:

"Error: Attribute loading not allowed on element img at this point."

一些文档:

Chrome 76 条发行说明 https://www.chromestatus.com/feature/5645767347798016

实现示例 https://www.searchenginejournal.com/google-chrome-will-soon-support-lazy-loading-at-the-browser-level/321211/

有人遇到同样的问题吗? 谢谢

我主要认为规范本身 (https://github.com/whatwg/html/pull/3752) 仍处于草案状态,因为事情仍在最终确定中。因此,验证者可能只是在考虑“稳定”或至少“不再处于草案状态”的功能以进行正确验证(或者只是尚未实施;-)可能出于与之前所述相同的原因)。

截至今天(2021 年),lazy-loading 已在所有主要浏览器中得到支持,并且现在已成为一个有效的标准(请参阅:img attributes on MDN and Lazy loading attributes on the WTAHWG specs)并且 W3C 的 HTML 验证器不会报告任何错误。

自 2019 年以来的 Nu HTML Checker (https://validator.w3.org/nu) still does but this has been reported as a bug (Add "a modern practices" mode #811),尽管它没有引起太多关注,但也许它会在某个时候得到解决。

根据caniuse.com目前浏览器支持如下:

在这里查看最新数据:https://caniuse.com/loading-lazy-attr

我猜你可以认为这个问题是验证器本身的错误,而不是你的代码。