Three solutions for js asynchronous loading _ javascript skills

Source: Internet
Author: User
By default, javascript is loaded synchronously, and javascript is blocked during loading. The following elements can be loaded only after javascript is loaded. How can this problem be solved, next, we will introduce three implementation solutions for asynchronous loading of js. If you are interested, refer to the following: by default, javascript is synchronously loaded, that is, javascript is blocked during loading, the subsequent elements can be reloaded only after javascript is loaded. For javascript that is not significant, loading will be slow if it is placed in the page header, it will seriously affect the user experience.

(1) defer, only supports IE
Defer attribute definition and usage (from w3school website)
The defer attribute specifies whether the script execution is delayed until the page is loaded.
Some javascript scripts use the document. write method to create the current document content. Other scripts are not necessarily the same.

If your script does not change the content of the document, you can add the defer attribute to the script tag to speed up document processing. Because the browser knows that it will be able to safely read the rest of the document without executing the script, it will postpone the interpretation of the script until the document has been displayed to the user.
Example:

The Code is as follows:


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.