简体   繁体   English

如何降低我在 PageSpeed Insights 上的 LCP 分数?

[英]How can I lower my LCP score on PageSpeed Insights?

Context:语境:

I recently finished my first ever project for a client (I'm 18 years old) & recently I've been trying to improve the web vitals to boost their SEO.我最近为一位客户(我 18 岁)完成了我的第一个项目,最近我一直在努力改进网络重要因素以提高他们的 SEO。

The biggest problem that I have is that my Largest Contentful Paint is too high which means that all of my URL's are marked as 'Poor' on the Search Console.我遇到的最大问题是我的最大内容绘制太高,这意味着我的所有 URL 在 Search Console 上都被标记为“差”。 I've spent hours on this now & read countless articles with 90% of the jargon going over my head.我现在已经在这上面花费了几个小时并阅读了无数文章,其中 90% 的术语都在我的脑海中。

Research/Attempts so far:迄今为止的研究/尝试:

I've compressed all of the images on the homepage, shortened, resized & compressed the video, I moved pretty much all of my files to minified versions linked by CDN's, I deferred most of my CSS, I added lazy loading for all of the images, I ensured that text remains visible for my fonts, I optimised my web hosting, minified most of my CSS/JS...我压缩了主页上的所有图像,缩短、调整大小和压缩视频,我将几乎所有文件移动到由 CDN 链接的缩小版本,我推迟了大部分 CSS,我为所有添加了延迟加载图像,我确保文本对我的字体保持可见,我优化了我的网络托管,缩小了我的大部分 CSS/JS...

But nothing I do seems to actually improve the LCP score by any meaningful amount.但我所做的一切似乎都没有真正提高 LCP 分数。 Even removing the video (the largest element) barely touched my scores...即使删除视频(最大的元素)也几乎没有触及我的分数......

This is a link to the Pagespeed Insights page:这是指向 Pagespeed Insights 页面的链接:

https://developers.google.com/speed/pagespeed/insights/?url=http%3A%2F%2Fprincestheatre.co.uk%2F&tab=mobile https://developers.google.com/speed/pagespeed/insights/?url=http%3A%2F%2Fprincestheatre.co.uk%2F&tab=mobile

And the website is princestheatre.co.uk .网站是princestheatre.co.uk

Am I (very likely) just being really stupid & missing something obvious or do I really need to fight over every millisecond here?我(很可能)只是真的很愚蠢并遗漏了一些明显的东西,还是我真的需要在这里争取每一毫秒?

I'd really appreciate any help, thank you :)我真的很感激任何帮助,谢谢:)

Improving LCP is hard, so you're not being stupid and it is not always obvious.改进 LCP 很难,所以你并不愚蠢,而且并不总是很明显。 And you are correct that most of the blog posts on the topic just re-format what you get on PageSpeed Insights.您是正确的,大多数关于该主题的博客文章只是重新格式化了您在 PageSpeed Insights 上获得的内容。 I build an app that is based on PageSpeed Insights but hopefully makes it more clear on what to do.我构建了一个基于 PageSpeed Insights 的应用程序,但希望能更清楚地说明要做什么。 I would encourage you to try it out and if you have specific questions, just reach out to me via the Chat app on the site.我鼓励您尝试一下,如果您有具体问题,请通过网站上的聊天应用程序与我联系。 And if you have any feedback on how to make the app better, I'd love to know.如果您对如何改进应用程序有任何反馈,我很想知道。

https://waterfaller.dev/?url=https://princestheatre.co.uk https://waterfaller.dev/?url=https://princestheatre.co.uk

You can take a look at the desktop and mobile results.您可以查看桌面和移动结果。 I would take a look at the top files that are slowing down your site.我会查看导致网站速度减慢的主要文件。

But to get you started that won't show up in these reports.但是为了让您开始,这些报告中不会显示。

The reason your LCP is failing is that you have both render-blocking stylesheets and also style blocks inside the tag.您的 LCP 失败的原因是您在标签中既有阻止渲染的样式表,也有样式块。 So to start I would get all my style tags into the or get them all into one stylesheet file.因此,一开始我会将所有样式标记放入 或将它们全部放入一个样式表文件中。 Then you can work on "critical CSS" which can be hard.然后你可以处理“关键 CSS”,这可能很困难。

Or if you want to avoid working on "critical CSS" then I would do the following,或者,如果您想避免使用“关键 CSS”,那么我将执行以下操作,

  1. get all your styles into 1-3 stylesheet files (for example do you need both bootstrap icons AND font awesome?)将所有样式放入 1-3 个样式表文件中(例如,您是否需要引导图标和字体都很棒?)
  2. Preload those stylesheets预加载这些样式表

https://developer.mozilla.org/en-US/docs/Web/HTML/Link_types/preload https://developer.mozilla.org/en-US/docs/Web/HTML/Link_types/preload

These stylesheets "block" the browser from starting to render the page.这些样式表“阻止”浏览器开始呈现页面。 So the goal is to load all the required CSS as fast as possible.所以目标是尽可能快地加载所有需要的 CSS。 You know that this is working if first contentful paint or start render times go down.您知道如果第一次内容绘制或开始渲染时间下降,这将起作用。

If they go down then your LCP will go down.如果它们下降,那么您的 LCP 就会下降。

Then I would figure out how to preload your fonts.然后我会弄清楚如何预加载你的字体。 Since you are self-hosting your fonts, this is pretty easy.由于您是自托管字体,因此这很容易。 And to make it easy I would just preload the woff2 fonts.为了方便起见,我将预加载 woff2 字体。

Start here as these address why the browser can't render the page faster.从这里开始解释为什么浏览器不能更快地呈现页面。 Then retest and see.然后重新测试看看。 Hint: you will want to figure out how to lazy load the video and images.提示:您需要弄清楚如何延迟加载视频和图像。 But I would not start there.但我不会从那里开始。

The Largest Contentful Paint (LCP) metric reports the render time of the largest image or text block visible within the viewport , relative to when the page first started loading.最大内容绘制 (LCP) 指标报告视口内可见的最大图像或文本块的渲染时间,相对于页面首次开始加载的时间。

LCP is ok and is in green in PSI for desktop, to resolve for mobile try rendering just text based content (no slider or anything fancy that requires JS, just text) for the top portion of your website and you will see improved result in LCP for mobile. LCP 没问题,在桌面的 PSI 中为绿色,要解决移动设备尝试仅渲染基于文本的内容(没有滑块或任何需要 JS 的任何花哨的东西,只需要文本)为您的网站的顶部,您将看到 LCP 中的改进结果为手机。

As this is your first project, I would propose to learn what the LCP is and is not.由于这是您的第一个项目,我建议了解 LCP 是什么,不是什么。 It's capital to understand it.理解它是资本。

Google's definition: The Largest Contentful Paint (LCP) metric reports the render time of the largest image or text block visible within the viewport relative to when the page first started loading. Google 的定义:Largest Contentful Paint (LCP) 指标报告相对于页面首次开始加载时在视口内可见的最大图像或文本块的渲染时间。

In other words, you can choose to design your way into selecting what will be the largest contentful paint and thus affect the score tremendously.换句话说,您可以选择设计自己的方式来选择内容最多的油漆,从而极大地影响分数。

One good trick is to look at what your LCP target is on the page by running lighthouse and looking at the LCP.一个很好的技巧是通过运行灯塔并查看 LCP 来查看页面上的 LCP 目标是什么。 That's how it looks in Lighthouse.这就是它在 Lighthouse 中的样子。

After you know what the LCP is, you can choose to modify the design a bit to select an LCP that will be fast by default (text, a small image).在您知道 LCP 是什么之后,您可以选择稍微修改设计以选择默认情况下速度很快的 LCP(文本、小图像)。 One of the dangers with the LCP is when you start displaying a picture/big block of text at the very end of your viewport, and it becomes the LCP. LCP 的危险之一是当您开始在视口的最末端显示图片/大文本块时,它就变成了 LCP。 In this situation introducing a space to pull that out of the viewport is perfectly fine (example).在这种情况下,引入一个空间将其拉出视口是非常好的(示例)。

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

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