Home > Web Front-end > JS Tutorial > Javascript loading and execution

Javascript loading and execution

伊谢尔伦
Release: 2016-11-22 13:12:06
Original
1082 people have browsed it

First of all, I want to talk about the loading and execution of Javascript. Generally speaking, browsers have two major characteristics for running Javascript: 1) it is executed immediately after loading, 2) when executed, it will block the subsequent content of the page (including the rendering of the page and the downloading of other resources). Therefore, if multiple js files are introduced, then for the browser, these js files are loaded serially and executed in sequence.

Because javascript may operate the DOM tree of the HTML document, browsers generally do not download js files in parallel like css files, because this is caused by the particularity of js files. Therefore, if your javascript wants to operate the subsequent DOM elements, basically the browser will report an error saying that the object cannot be found. Because when Javascript is executed, the subsequent HTML is blocked, and there is no subsequent DOM node in the DOM tree. So the program reported an error.

Traditional way

So, when you write the following code in the code:

<scripttype="text/javascript"  src="http://coolshell.cn/asyncjs/alert.js"></script>
Copy after login

Basically speaking, the

Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template