The difference between script async and script defer

Source: Internet
Author: User

The browser to the JS file operation has two main parts: Download and execution;

JS file download In some browsers is parallel, in some browsers are serial, such as: IE8, Firefox3, chrome2 are serial download;

Execution in all browsers is blocked by default, when JS in the execution of HTML parsing and other operations, so, the top of the page JS should not be too large, the conference caused the page long time in a blank state, for the outside chain of JS files, async and defer attributes can reduce the impact of page loading

Async Indicates whether JS executes asynchronously, when this property does not block the loading of the current page, and immediately after the JS download, but do not guarantee the execution order of multiple script tags

Defer indicates whether JS deferred execution, when there is this attribute, JS execution will be deferred until the completion of page parsing, can guarantee the execution order of multiple script tags, It is important to note that these two properties are currently invalid for inline JS and are asynchronous in the browser for script tags created in the DOM

If Async is true, then the script executes asynchronously after the download is complete

If Async is False,defer true, then the script executes after the page is parsed

If both async and defer are false, then the script stops parsing the page in the page parsing, immediately downloads and executes

Note: This article is from excerpt

The difference between script async and script defer

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.