Home > Web Front-end > JS Tutorial > body text

Detailed explanation of loading and execution in JavaScript

迷茫
Release: 2017-03-26 15:14:56
Original
1467 people have browsed it

Following the previous article "Introduction to Browser Rendering Principles", this article talks about the loading and execution of JavaScript.

Generally speaking, browsers have two major features for running JavaScript:

1) Execute immediately after loading

##2 ) will block subsequent content of the page (including page rendering and download of other resources) when executed

So, if multiple JS files are introduced, then for the browser, these JS files will be loaded serially and executed one after another.

Since JavaScript may operate the DOM tree of the HTML document, browsers generally do not download JS files in parallel like they download CSS files in parallel. This is due to the particularity of JS files. Therefore, if your JavaScript wants to operate the subsequent DOM elements, the browser will report an error saying that the object cannot be found. This is because the subsequent HTML is blocked when JavaScript is executed, and there are no subsequent nodes when operating the DOM tree.

The traditional way

When you write the following code:

Copy after login

Basically , the
Copy after login

The dialog box that pops up is:

loadjs() exit...
loadjs() finished!
hello world
another block
Copy after login

Then the page will be displayed.

#script defer and asyncattributes

IE defer tag since IE6 , such as:

Copy after login

For IE, this tag will cause IE to download the JS file in parallel, and hold its execution until the entire DOM is loaded. Multiple defer
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!