Delayed loading of JavaScript

Source: Internet
Author: User
Delayed loading of JavaScript

How to delay loading JavaScript

The real delayed loading of JavaScript means that loading or parsing JavaScript starts after the page content has been fully loaded (that is, JavaScript cannot affect the page speed or key rendering path ).

  • Use the onload event to call external JavaScript Resources

  • External JavaScript resources cannot be loaded before the page content is loaded.

  • The external JavaScript resource starts to run after the content is loaded and affects the page.

Explanation

The focus on the network is often that people are crazy about finding a solution, and the delay loading of JavaScript is one of the focuses.

Many people say "you only need to use defer", "You only need to use async", or "you just need to put your JavaScript at the bottom of the page", but none of them solve the problem-let the page be fully loaded and then (only after the full load) Load External JS. These methods won't give you a warning of "loading JavaScript with delay" obtained from the Google Page Speed Tool (this is a bit of a question for the translator, because I found that the above three methods can remove this warning during the test ).

This solution will be answered.

Scripts that call external JavaScript files

Put this code in the HTML documentBefore the tag (near the bottom of the HTML document ). The external script name isdefer.js.

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.