简体   繁体   English

延迟折叠的CSS渲染器突然无法通过Google Pagespeed Insight Test

[英]deferring above the fold CSS render suddenly fails to pass Google Pagespeed Insight Test

Can someone tell me why the following working render delay scripts suddenly fails to pass Google Pagespeed Insight Test ? 有人可以告诉我为什么以下工作的渲染延迟脚本突然无法通过Google Pagespeed Insight Test吗?

<script>
function loadCSS(href){
var ss = window.document.createElement('link'),
ref = window.document.getElementsByTagName('head')[0];
ss.rel = 'stylesheet';
ss.href = href;
// temporarily, set media to something non-matching to ensure it'll
// fetch without blocking render
ss.media = 'only x';
ref.parentNode.insertBefore(ss, ref);
setTimeout( function(){
// set media back to `all` so that the stylesheet applies once it loads
ss.media = 'all';
},0);
}
loadCSS('link.css');
</script>

<noscript>
<!-- Let's not assume anything -->
 <link rel="preload" href="link.css" as="style" onload="this.rel='stylesheet'">

</noscript> 

The page is http://www.landshoppe.com/ 该页面是http://www.landshoppe.com/

I am using 我在用

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js" data-pagespeed-orig-type="text/javascript" async></script>

at the footer 在页脚

Finally I found the answer. 终于我找到了答案。 This answer could be useful for someone who is breaking his head over how to get the Google pagespeed score right ! 这个答案对于那些在如何正确获取Google pagespeed得分方面有些头绪的人很有用!

I think I have almost cracked it. 我想我快要破解了。 I have got a 98 in Desktop and 94 in Mobile. 我在台式机上有98,在移动版上有94。 Moving to clinch the perfect 100 soon ! 即将争取完美100! :) :)

Optimization of CSS that blocks render 'Above the Fold' (ATF) basically means having all 'Above the Fold' styles to be 'inlined' before the 'head' and inside 'style' tags (Don't leave even one ATF class or id in the .css file) ! 对阻止渲染“折叠后”(ATF)的CSS的优化基本上意味着将所有“折叠前”样式都“内联”在“ head”标签和“ style”标签内(甚至不要留下一个ATF类或.css文件中的ID)! And stuff everything else into the external css file and dump it at the footer, or defer it with javascript or any other method you like and Google Pagespeed Insight will be happy to ignore it ! 并将其他所有内容填充到外部css文件中,然后将其转储到页脚中,或者使用javascript或您喜欢的任何其他方法将其推迟,Google Pagespeed Insight会很乐意忽略它! :) If you leave even one class or Id inside the css file, GPS will simply make your perfect-score life miserable by tirelessly yelling 'Render Blocking CSS' ! :)如果您在css文件中甚至只留下一个类或ID,GPS都会不知疲倦地大喊“ Render Blocking CSS”,从而使您的完美人生简直是惨不忍睹! Even after you do everything to defer it ! 即使您竭尽所能延后了!

Forget everything you learnt about not inlining any CSS and putting it all in an external file ! 忘记关于不内联任何CSS并将其全部放入外部文件的所有知识! :) :)

Cheers ! 干杯!

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

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