JS script synchronization, asynchronous and delay

Source: Internet
Author: User

In general, when we introduce JS file through SRC, we recommend introducing it at the end of the page because it blocks the rendering of the page. Defer and async can achieve the same effect

When the HTML parser encounters the <script> element, it must execute the script before resuming parsing and rendering of the document.

Script execution is designed to be synchronized and blocked by default, and we can add defer and async attributes to the script tag (not all browser support, of course)

Using the defer and Async properties, the browser can continue to parse and render documents while downloading scripts

If the label has both properties, the Defer property is automatically ignored when both the defer and async properties are supported

As follows:

<script defer src= "aa.js" ></script><script async src= "Bb.js" ></script>

Attention:

Deferred scripts are executed in the order in which they appear in the document, while asynchronous scripts execute after they are loaded (the order may be unordered).

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.