简体   繁体   English

如何消除渲染阻塞JavaScript

[英]How to eliminate render-blocking JavaScript

I was testing the web page loading with Google PageSpeed tool . 我正在使用Google PageSpeed工具测试网页加载。 The result says "Eliminate render-blocking JavaScript and CSS in above-the-fold content" for 结果显示“消除渲染阻止JavaScript和CSS的首要内容”

<script type='text/javascript' src='http://example.com/wp-includes/js/jquery/jquery.js?ver=1.11.2'></script>
<script type='text/javascript' src='http://example.com/wp-includes/js/jquery/jquery-migrate.min.js?ver=1.2.1'></script>

The source code is: 源代码是:

<head>
...
...

<script>(function(){document.documentElement.className='js'})();</script>
...
...
</head>

I'm keen to add a async or defer tag. 我很想添加一个异步或延迟标签。 How can I achieve this? 我怎样才能做到这一点?

From MDN about the async attribute: MDN关于异步属性:

It has no effect on inline scripts (ie, scripts that don't have the src attribute). 它对内联脚本(即没有src属性的脚本)没有影响。

The same is true about the defer attribute. defer属性也是如此。

Basically, if you really want to get rid of the error, just move that to just before the </body> tag. 基本上,如果你真的想摆脱错误,只需将它移到</body>标记之前。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM