开发者

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

开发者 https://www.devze.com 2023-02-19 22:06 出处:网络
I mean if I append some contents like this: <body> //contents <script>body.appendChild(\'<img src=\"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 开发者_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

精彩评论

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