简体   繁体   中英

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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