简体   繁体   English

如何停止渲染阻止Javascript和CSS?

[英]How to stop render-blocking Javascript and CSS?

I have tested my page on Google PageSpeed Insights and It keeps saying "Eliminate render-blocking JavaScript and CSS in above-the-fold content" 我已经在Google PageSpeed Insights上测试了我的页面,并且一直说“在首屏内容中消除渲染阻止的JavaScript和CSS”

It says I have 17 blocking scripts and 11 blocking CSS resources. 它说我有17个阻止脚本和11个阻止CSS资源。

I have tried moving all of the JS to the bottom of the page to load it last however Google is still saying I have render-blocking JS... 我试图将所有JS移到页面底部以最后加载它,但是Google仍然说我有阻止渲染的JS ...

Does anyone know how I can solve this? 有谁知道我该怎么解决?

Thank you in advance for any help. 预先感谢您的任何帮助。

You need to dig more into Critical Rendering Path study. 您需要深入研究“ 关键渲染路径”研究。

Simple Rule: In your webpage load only things which are really important to show to user. 简单规则:在您的网页中,仅加载对用户显示非常重要的内容。 Rest things can be loaded after page load has been done. 页面加载完成后,即可加载其余内容。

When JS is being downloaded on page, it stops DOM generation and hence stop downloading other resources. 当在页面上下载JS时,它将停止DOM生成并因此停止下载其他资源。 Putting JS at bottom will work but still it will block your rendering when JS is being downloaded. 将JS放在底部将可以使用,但在下载JS时仍然会阻止渲染。 Just to overcome this issue it is suggested to add async tag to your script tag. 为了解决这个问题,建议在脚本标签中添加async标签。 But adding async can lead to other issues. 但是添加async可能会导致其他问题。 See here . 看这里 More reading about this can be found here . 有关此内容的更多信息,请参见此处

Same case applies to CSS but advantages is that it will not block DOM generation. 同样的情况也适用于CSS,但是优点是它不会阻止DOM的生成。 More reading about this can be found here . 有关此内容的更多信息,请参见此处

Hi I tried it but it slowed down the website not sure why so put it back saying Eliminate render-blocking JavaScript and CSS on Googles page insite. 嗨,我尝试过,但是它使网站变慢,不确定为什么要放回去,说在Google网站页面上消除渲染阻止的JavaScript和CSS。

If any one knows why by removing the blocking css it slowed down the website enter image description here 如果有人知道为什么通过删除阻止CSS来减慢网站速度,请在此处输入图片描述

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

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