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

Detailed explanation of loading and execution in JavaScript

迷茫
Release: 2017-03-26 15:14:56
Original
1618 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:

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

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