简体   繁体   English

Google Pagespeed Insight:“优化以下内容的CSS交付”。 如何?

[英]Google Pagespeed Insight: “Optimize CSS Delivery of the following”. How to?

I tested my wordpress website on Google Page Speed Insight and it scored a 95/100. 我在Google Page Speed Insight上测试了我的wordpress网站,得分为95/100。 It suggested that I should "Optimize CSS Delivery" of 1 css file: 它建议我应该“优化CSS交付”1 css文件:

<link rel="stylesheet" type="text/css" href="<?php echo get_stylesheet_uri(); ?>" />

Right now it's sitting in the footer along with all the javascript codes below it. 现在它和页脚下面的所有javascript代码一起坐在页脚中。 I moved it back between the head tag and same results. 我把它移回头标签和相同的结果之间。 How do I optimized the css delivery of the css file? 如何优化css文件的css传送?

In the case of a large CSS file, you will need to identify and inline the CSS necessary for rendering the above-the-fold content and defer loading the remaining styles until after the above-the-fold content. 在大型CSS文件的情况下,您需要识别和内联渲染上层内容所需的CSS,并推迟加载剩余样式,直到上面的内容为止。

Taken from: https://developers.google.com/speed/docs/insights/OptimizeCSSDelivery 摘自: https//developers.google.com/speed/docs/insights/OptimizeCSSDelivery

Its not best to actually put all the css together. 实际上把所有的css放在一起并不是最好的。 You should call first the styling that is needed for the rendering and afterwards call that big stylesheet of yours. 您应首先调用渲染所需的样式,然后调用您的大样式表。

And if you want to know how to defer stylesheets well this is how: 如果你想知道如何推迟样式表,那么这是如何:

CSS delivery optimization: How to defer css loading? CSS交付优化:如何推迟css加载?

Hope i got you covered :) 希望我能帮到你:)

95/100 is a great score. 95/100分数很高。 You're at the point where more work to hit 100 is going to give you diminishing returns compared to the effort involved with getting there. 与达到目标所做的努力相比,你现在正处于达到100的更多工作会给你带来收益递减的程度。

But if you're dead set on approaching 100/100 you'll need to remove the above the fold CSS from the file and include it in a <style> block within your theme. 但是如果你已经死了接近100/100,你需要从文件中删除上面的折叠CSS并将其包含在主题中的<style>块中。 Then you can hold off on loading the CSS file until the rest of the page has loaded and it will no longer be render blocking. 然后你可以暂停加载CSS文件,直到页面的其余部分加载完毕,它将不再是渲染阻止。

Here's some info I wrote on handling above the fold CSS with the WordPress Autoptimize plugin including a JavaScript bookmarklet to get you started with finding your above the fold CSS. 这里有一些关于使用WordPress Autoptimize插件处理上面的CSS的信息,包括一个JavaScript书签,让你开始找到你的折叠CSS。

Note: You should be using the wp_enqueue_style() function to include that script, rather than include it directly in the footer. 注意:您应该使用wp_enqueue_style()函数来包含该脚本,而不是将其直接包含在页脚中。 Check out this article on my website to see how to enqueue scripts and styles properly. 在我的网站上查看这篇文章 ,了解如何正确地排列脚本和样式。

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

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