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.