This rule is triggered when PageSpeed Insights detects that your HTML refers to a system-blocked external JavaScript file (located in the first part of the page).
The browser must parse the web page before it can be rendered to the user. If the browser encounters an external script blocked by the system during parsing, it must stop parsing and download the JavaScript. Every time this happens, the browser adds a network round trip, which causes a delay in rendering the web page for the first time.
It is recommended that you handle the JavaScript needed to render the first screen area inline, and let the JavaScript needed to add other functions to the web page delay loading until the first screen content is sent. Note that to shorten the load time in this way, you must also
优化CSS发送过程.
If external scripts are small, you can add them directly to HTML documents. Embedding smaller files in this way allows the browser to continue rendering web pages. For example, if the HTML document looks like this:
资源small.js
As shown below:
/* contents of a small JavaScript file */
那么,您即可按如下这样内嵌脚本:
这样,您就可以将small.js
Embedded in the HTML document, thus eliminating external requests for it.
为防止JavaScript阻止网页加载,建议您在加载JavaScript时使用HTML异步属性。例如: