Learning javascript file loading optimization _ javascript skills

Source: Internet
Author: User
This article mainly introduces javascript file loading optimization in detail, and implements js file loading optimization in three ways. if you are interested, refer to the js engine section for details, when the rendering engine parses the script tag, it gives control to the JS engine. if the script loads external resources, it must wait until the download is complete before execution. Therefore, here we can perform a lot of optimization work on it.

Placed at the bottom of the BODY

To enable the rendering engine to render the DOM tree as early as possible, we need to place the script at the bottom of the body so that the page can be removed from the white screen as soon as possible, that is, the DOMContentLoaded event will be triggered early. however, in IOS Safari, Android browser, and IOS webview, even if you put the js script at the end of the body, the results are the same. Therefore, you need to perform other operations to optimize js file loading.

DEFER loading

This is a script attribute defined in HTML4. it is used to indicate that when a rendering engine encounters a script, if the script references an external resource, it will be temporarily suspended and loaded. The rendering engine continues to parse the following HTML documents. after parsing, the script in the script is executed.

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.