开发者

do content added to DOM count for the total page load time?

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 开发者_Go百科or it will take in consideration the load of the new image too? (new.png) ?


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...

var img = new Image;

img.src = 'http://www.gravatar.com/avatar/3535689c965d66db3d2a936ced96192a?s=32&d=identicon&r=PG';
img.alt = 'Example';

document.body.appendChild(img);

jsFiddle.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜