简体   繁体   English

消除渲染阻止javascript - 谷歌开发者建议摘要

[英]Eliminate render-blocking javascript - google developers suggestions summary

Google developer tool insist - that I move my modernizr .js to the end of </body> tag, As I understand If I will do so html5 tags will not be supported by ie8 and ie7. 谷歌开发人员工具坚持 - 我将我的modernizr .js移动到</body>标签的末尾,据我了解如果我这样做,ie8和ie7将不支持html5标签。 (New version of modernizr enables html5 tags support for older browsers) (新版本的modernizr支持旧版浏览器支持html5标签)

Is there any solution for that? 那有什么解决方案吗?

Thanks 谢谢

2017 Note: This original answer is correct in relation to Modernizr, html5shiv and HTML 5 elements in IE 9 and under. 2017注意:这个原始答案对于IE 9及以下版本的Modernizr,html5shiv和HTML 5元素是正确的。 Do you even need IE9 in your project? 你甚至在项目中需要IE9吗? IE9 and under accounts for ~0.50% of usage . IE9及其下约占用量的0.50% These browsers are not even supported by Microsoft anymore and have not been since January 6, 2016. Head to "Modernizr Download Builder" to appropriately build and setup your Modernizr file and base HTML page. 微软甚至不支持这些浏览器,自2016年1月6日起,这些浏览器还没有。请前往“Modernizr Download Builder”,以适当地构建和设置您的Modernizr文件和基本HTML页面。 If you don't need this old IE support, drop html5shiv and drop the need to stick it in the HEAD . 如果您不需要这个旧的IE支持,请删除html5shiv并放弃将其粘贴在HEAD的需要。

Original Answer 原始答案

It's a suggestion and should generally be used; 这是一个建议,通常应该使用; however, the case of including the modernizr.js file to enable HTML 5 must be done before the body tag. 但是,包含modernizr.js文件以启用HTML 5的情况必须在body标签之前完成。 As such, you should ignore this suggestion. 因此,您应该忽略此建议。 Per Modernizr docs ( "Installing Modernizer" ), for best performance you should stick them after your stylesheet references. 根据Modernizr docs( “安装Modernizer” ),为了获得最佳性能,您应该在样式表引用后粘贴它们。

If you're using modernizr's included yepnope.js to conditionally load scripts or doing any other sort of setup that can go before the closing of the body though. 如果你正在使用包含yeznope.js的modernizr来有条件地加载脚本或进行任何其他类型的设置,可以在关闭身体之前进行。

There is a way to overcome that. 有一种方法可以克服这个问题。 By defining a dummy condition which stops the render-blocking. 通过定义一个停止渲染阻塞的虚拟条件。

Eg: 例如:

<head>
...
<!--[if]><script src="vendor/modernizr.js"></script><![endif]-->
...
</head>

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

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