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

JavaScript loading: defer and async

藏色散人
Release: 2019-05-09 09:35:56
forward
2416 people have browsed it

JavaScript loading: defer and async

The parsing process of the page is single-threaded, but single-threaded can also be divided into synchronous and asynchronous. There are three ways to interpret script tags: default, defer and async.

Copy after login

Default mode, the browser will load and execute the specified script immediately. "Immediately" refers to before rendering all document content after the script tag, which means that it does not wait for subsequent loading of document elements. , load and execute after reading.

Copy after login

async loading mode, the process of loading and rendering subsequent document elements, script.js is loaded asynchronously, and script.js is executed synchronously after script.js is loaded (possibly during the process of subsequent document element parsing being completed) )

Copy after login

defer loading mode, the process of loading and rendering subsequent document elements, script.js is loaded asynchronously, and script.js is executed synchronously after script.js loading is completed and subsequent document element parsing is completed

JavaScript loading: defer and async

Script tag parsing time graph

Only the two attributes of the script tag linked with the src attribute are effective.

Copy after login

Script tags without the src attribute are loaded sequentially when the document is loaded. These two attributes are invalid.

Copy after login

The above is the detailed content of JavaScript loading: defer and async. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:aliyun.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Popular Tutorials
More>
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!