How to stop render-blocking Javascript and CSS?

孤街醉人 提交于 2019-12-12 01:24:16

问题


I have tested my page on Google PageSpeed Insights and It keeps saying "Eliminate render-blocking JavaScript and CSS in above-the-fold content"

It says I have 17 blocking scripts and 11 blocking CSS resources.

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...

Does anyone know how I can solve this?

Thank you in advance for any help.


回答1:


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. Putting JS at bottom will work but still it will block your rendering when JS is being downloaded. Just to overcome this issue it is suggested to add async tag to your script tag. But adding async can lead to other issues. 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. More reading about this can be found here.




回答2:


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.

If any one knows why by removing the blocking css it slowed down the website enter image description here



来源:https://stackoverflow.com/questions/30547812/how-to-stop-render-blocking-javascript-and-css

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!