添加到 DOM 的内容是否计入页面总加载时间?
我的意思是,如果我附加一些这样的内容:
<body>
//contents
<script>body.appendChild('<img src="new.png">');
// other contents
</body>
浏览器将仅考虑原始 html 来触发 window.onload 还是也会考虑新图像的加载? (new.png
)?
I mean if I append some contents like this:
<body>
//contents
<script>body.appendChild('<img src="new.png">');
// other contents
</body>
the browser will fire window.onload considering only the original html or it will take in consideration the load of the new image too? (new.png
) ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
除了代码/标记不正确之外,它还会考虑新图像。将其附加到 DOM 将下载
src
属性指向的任何内容。但是,如果将此代码放置在
window.onload = function() { ... }
内,则不会考虑它,因为在加载窗口之前不会进行下载。这是实际有效的代码...
jsFiddle。
Besides that code/markup being incorrect, it will consider the new image. To append it to the DOM will be to download whatever the
src
attribute points to.However, if this code was placed inside of a
window.onload = function() { ... }
, then it wouldn't be considered because its download would not occur until your window was loaded.Here is the code that would actually work...
jsFiddle.