简体   繁体   English

空的SRC属性和较差的性能

[英]Empty SRC attributes and poor performance

Recently I read this article by Nicholas C. Zakas: 最近,我读了Nicholas C. Zakas的这篇文章:

http://www.nczonline.net/blog/2009/11/30/empty-image-src-can-destroy-your-site/ http://www.nczonline.net/blog/2009/11/30/empty-image-src-can-destroy-your-site/

It says that empty SRC attributes in IMG and SCRIPT files for example can cause poor performance. 它说,例如IMG和SCRIPT文件中的空SRC属性可能会导致性能下降。 My question is: 我的问题是:

Are there still the same performance issues if there is NO src attribute at all? 如果根本没有src属性,是否仍然存在相同的性能问题?

Example: 例:

<img id="image" />

Also, how will the browser interpret this? 另外,浏览器将如何解释呢? Would the above code be problematic anywhere? 上面的代码在任何地方都会有问题吗?

Much obliged for any help. 非常有必要提供任何帮助。

This is from a very old version of the HTML spec : 这来自HTML规范的一个很旧的版本

SRC (Source) SRC(来源)

The SRC attribute specifies the URI for the image to be embedded. SRC属性指定要嵌入图像的URI。 Its syntax is the same as that of the HREF attribute of the tag. 其语法与标记的HREF属性相同。 SRC is mandatory. SRC是强制性的。

@src is required, so if you have an <img> with missing @src , then it wouldn't be a valid HTML. @src是必需的,因此如果您的<img>缺少@src ,那么它将不是有效的HTML。 Browsers are very tolerant though, but what they will do in this situation is probably implementation specific. 浏览器虽然非常宽容,但是在这种情况下,它们可能会执行特定于实现的操作。

EDIT: from HTML 5 spec : 编辑: 从HTML 5规范

The src attribute must be present , and must contain a valid non-empty URL potentially surrounded by spaces referencing a non-interactive, optionally animated, image resource that is neither paged nor scripted. src属性必须存在 ,并且必须包含有效的非空URL,该URL可能被引用非分页或脚本化的非交互式,可选动画的图像资源的空格所包围。

So, an <img> with missing or empty @src would not be valid HTML. 因此,缺少或空白@src<img>将不是有效的HTML。

AFAIK, HTML 5 still does not specify how browsers should handle missing src attribute, although it did say: AFAIK,HTML 5仍然没有指定浏览器应如何处理缺少的src属性,尽管它确实指出:

If the src attribute is not set and either the alt attribute is set to the empty string or the alt attribute is not set at all 如果未设置src属性,并且alt属性设置为空字符串,或者根本未设置alt属性

The element represents nothing. 元素代表什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM