简体   繁体   English

灯塔上最大的满意油漆 (LCP) 是 ap 标签。 (使用盖茨比)

[英]Largest contententful paint (LCP) on lighthouse is a p tag. (Using gatsby)

I don't know why my LCP would be ap tag, and I have no idea what I would do to reduce the size of it.我不知道为什么我的 LCP 会是 ap 标签,我也不知道我会做些什么来减小它的大小。 Sometimes it gets up to 2.6s and gives a yellow rating(instead of green).有时它会达到 2.6 秒并给出黄色评级(而不是绿色)。

在此处输入图像描述

This is the p tag.这是 p 标签。 All of those classes are bootstrap classes.所有这些类都是引导类。

<p className="text-center mb-md-5 mt-0 mb-5">{aboutText}</p>

This is the variable aboutText这是关于aboutText的变量

const aboutText = `Suddenly  Magazine highlights the uniqueness of Saskatchewan,  and its sudden rise in popularity and growth mentioned in publications such as USA Today and the New York Times.

Advertorials and Articles focus on its rare & particular tourism, its passionate sports, its character, and the prosperous opportunity for businesses and artists influenced by a Saskatchewan setting.

It is centred in Saskatoon, but contributors range from Lac La Ronge in the North, to provincial boundaries east and west, to the Outlaw Caves near the US border.`

The domain is https://suddenlysask.com域是https://suddenlysask.com

So why is your LCP a p tag?那么为什么你的 LCP 是一个p标签呢?

Its only on mobile ap tag, and here take a look at the mobile size.它只在移动 ap 标签上,这里看看移动大小。

在此处输入图像描述

Its clearly to see that the p tag takes the most place here.可以清楚地看到p标签在这里占据了最多的位置。

You could try to make the image bigger on mobile devices, so lighthouse will count the image as the LCP.您可以尝试在移动设备上将图像放大,以便灯塔将图像计为 LCP。

Another solution is to split up your p tag into 2 smaller p tags另一种解决方案是将您的p标签分成 2 个较小的p标签

Another solution could be (witch is not recommended) to cut your p tag slightly out of the viewport because...另一种解决方案可能是(不推荐使用女巫)将您的p标签稍微从视口中剪掉,因为...

The size of the element reported for Largest Contentful Paint is typically the size that's visible to the user within the viewport.为最大内容绘制报告的元素大小通常是用户在视口中可见的大小。 If the element extends outside of the viewport, or if any of the element is clipped or has non-visible overflow, those portions do not count toward the element's size.如果元素延伸到视口之外,或者任何元素被剪裁或具有不可见的溢出,则这些部分不计入元素的大小。

I guess your bad result comes from this line here:我猜你的坏结果来自这里的这条线:

<link data-react-helmet="true" rel="preload" href="https://fonts.googleapis.com/css?family=Montserrat|Helvetica+Neue|Helvetica|Arial&amp;display=swap">

Why does it take up to 2.6 sec?为什么最多需要 2.6 秒?

Here is what i guess:这是我的猜测:

Loading the google font can take its time and its not guaranteed that it loads always exactly the same time, so when the font is loaded it will swap your fonts and that means the p tag swaps.加载谷歌字体可能需要一些时间,并且不能保证它总是在同一时间加载,所以当字体加载时,它会交换你的 fonts ,这意味着p标签交换。 That means that the p tag with the new font is treated as new LCP.这意味着带有新字体的p标签被视为新的 LCP。

For testing purposes you could try to remove the link and see if it affects your speed score at your LCP出于测试目的,您可以尝试删除该link ,看看它是否会影响您在 LCP 的速度得分

At the end, i would split the paragraph up into 2 smaller paragraphs so that the image is the LCP.最后,我会将段落分成 2 个较小的段落,以便图像是 LCP。 i think its the easiest solution.我认为这是最简单的解决方案。

People seems to completely misunderstand the purpose of the Largest Contentful Paint metric.人们似乎完全误解了最大内容绘制指标的目的。 It is designed to show you when the majority of the above the fold content is ready.它旨在向您显示上述折叠内容的大部分何时准备就绪。

What item is the Largest Contentful Paint is not as important as when it occurs.什么项目是最大的内容绘画并不像它发生的时间那么重要。 What item is only useful in determining what could be slowing your page down.哪些项目仅在确定可能会减慢您的页面速度时有用。

It is the main metric in determining when 'above the fold' content is painted sufficiently that an end user would see the page as "complete" (this is perceived completeness, there can still be stuff loading lower down the page / in the background).这是确定“首屏”内容何时被充分绘制以使最终用户将页面视为“完整”的主要指标(这是感知的完整性,仍然可以在页面下方/后台加载内容) .

The suggestions of splitting the paragraph, wrapping it in a div, making it taller etc. etc. serve no purpose , they just shift the LCP onto something else (possibly) making your score look better but not actually fixing the problem.拆分段落,将其包装在 div 中,使其更高等的建议没有任何意义,它们只是将 LCP 转移到其他东西上(可能)使您的分数看起来更好,但实际上并没有解决问题。

What you want to do is optimise the initial content on the page.您要做的是优化页面上的初始内容。

For this you want to serve just the 'above the fold' HTML along with the CSS and JS required for above the fold content.为此,您只想提供“首屏” HTML 以及首屏内容所需的 CSS 和 JS。

Then you serve everything else.然后你为其他一切服务。

This article is a good introduction to critical JS and CSS https://www.smashingmagazine.com/2015/08/understanding-critical-css/这篇文章很好的介绍了关键JS和CSS https://www.smashingmagazine.com/2015/08/understanding-critical-css/

However in a nutshell inlining critical CSS and JS means that the CSS and JS required to render the initial content on the page should be inline within the HTML .然而,简而言之,内联关键 CSS 和 JS 意味着在页面上呈现初始内容所需的 CSS 和 JS 应该内联在 HTML中。 Now I am guessing with something like Gatsby you would inline the critical JS that renders the above the fold content, above the fold CSS etc. but the principle is the same.现在我猜测像 Gatsby 这样的东西你会内联呈现上述折叠内容、折叠 CSS 等的关键 JS,但原理是一样的。

The key is that the above the fold content should all be served (except for non vector images) within the HTML so that there is no round-trip time waiting for CSS files, JS files etc.关键是上述折叠内容都应该在 HTML 内提供(非矢量图像除外),这样就没有等待 CSS 文件、JS 文件等的往返时间。

So for clarity instead of:-因此,为了清楚起见,而不是:-

  • HTML requested, (200ms round trip to server) HTML 请求,(200ms 往返服务器)
  • HTML loaded and parsed, links to CSS and JS found required to render the initial page content HTML 加载和解析,链接到 CSS 和 JS 发现需要呈现初始页面内容
  • CSS and JS requested. CSS 和 JS 请求。 (200ms round trip to server) (到服务器的 200 毫秒往返)
  • CSS and JS loaded CSS 和 JS 加载
  • Enough to render the page.足以渲染页面。

Instead you have相反,你有

  • HTML requested, (200ms round trip to server) HTML 请求,(200ms 往返服务器)
  • HTML loaded, all required CSS and JS inlined in HTML HTML 已加载,所有必需的 CSS 和 JS 内联在 HTML
  • Enough to render the page足以渲染页面

This may not seem like a lot but that 200ms can make a huge difference to perceived speed.这可能看起来不多,但 200 毫秒可以对感知速度产生巨大影响。

Also this is a simplified example, often a page requires 20 requests or more to render the above the fold content.这也是一个简化的示例,通常一个页面需要 20 个或更多请求来呈现上述折叠内容。 Due to the limitations of 8 requests at a time (normally) this means there could be up to 3 round-trips of 200ms waiting for server responses.由于一次有 8 个请求的限制(通常),这意味着最多可能有 3 个 200 毫秒的往返等待服务器响应。

Looking at your site you will be getting a false reading for "critical request chains" as there is no HTML served in the initial page as it is all rendered via JS.查看您的站点,您将得到“关键请求链”的错误读数,因为初始页面中没有提供 HTML,因为它都是通过 JS 呈现的。 This could be why you do not think there is a problem.这可能就是您认为没有问题的原因。

If you do the above your will get low FCP and LCP times assuming your images are optimised.如果您执行上述操作,假设您的图像已优化,您将获得较低的 FCP 和 LCP 时间。

There are some Gatsby users complaining recently about a huge fall and decreasing of Lighthouse score and everyone agrees on the same: the score of the Lighthouse has decreased a lot due to a high LCP (Largest Contentful Paint) response time.最近有一些 Gatsby 用户抱怨 Lighthouse 分数大幅下降和下降,每个人都同意这一点:由于 LCP(Largest Contentful Paint)响应时间过长,Lighthouse 的分数下降了很多。

This is the result of the changes in the new Lighthouse version (v6) which in fact, introduces the LCP as a new concept and metric.这是新 Lighthouse 版本 (v6)更改的结果,实际上,它引入了 LCP 作为新概念和度量标准。 As you can see, the changelog was written in may but depends on the user, and on the site, the changes arrive on different dates (I guess that depends on Google's servers and the time that this change replicates through them).如您所见,更改日志可能写入但取决于用户,并且在站点上,更改到达的日期不同(我想这取决于 Google 的服务器以及此更改通过它们复制的时间)。

According to the documentation:根据文档:

Largest Contentful Paint (LCP) is a measurement of perceived loading experience. Largest Contentful Paint (LCP)是对感知加载体验的衡量。 It marks the point during page load when the primary–or "largest"–content has loaded and is visible to the user.它在页面加载期间标记主要或“最大”内容已加载并且对用户可见的点。 LCP is an important complement to First Contentful Paint (FCP) which only captures the very beginning of the loading experience. LCP 是 First Contentful Paint (FCP) 的重要补充,它只捕获加载体验的最开始。 LCP provides a signal to developers about how quickly a user is actually able to see the content of a page. LCP 向开发人员提供了一个信号,即用户实际能够多快地查看页面内容。 An LCP score below 2.5 seconds is considered 'Good.' LCP 分数低于 2.5 秒被认为是“好”。

As you said, this metric is closely related to FCP and it's a complement of it: improving FCP will definitely improve the LCP score.正如你所说,这个指标与 FCP 密切相关,是它的补充:提高 FCP 肯定会提高 LCP 分数。 According to the changelog:根据变更日志:

FCP's weight has been reduced from 23% to 15%. FCP 的权重已从 23% 降至 15%。 Measuring only when the first pixel is painted (FCP) didn't give us a complete picture.仅在绘制第一个像素(FCP)时进行测量并不能为我们提供完整的画面。 Combining it with measuring when users are able to see what they most likely care about (LCP) better reflects the loading experience.将其与衡量用户何时能够看到他们最可能关心的内容 (LCP) 相结合,可以更好地反映加载体验。

You can follow this Gatsby GitHub thread to check how the users bypass this issue in other cases.您可以按照这个Gatsby GitHub 线程来检查用户在其他情况下如何绕过此问题。

In your case, I would suggest:在你的情况下,我建议:

  • Delete your <p> and check the score again to see the changes (just to be sure).删除您的<p>并再次检查分数以查看更改(只是为了确定)。
  • Wrapping your <p> inside a <div> .将您的<p>包装在<div>中。
  • Splitting your <p> in 2 or 3 small pieces to make them available for the LCP as well as FCP.将您的<p>分成 2 或 3 小块,以使它们可用于 LCP 和 FCP。

If none of the above work, I would try playing on <p> 's height to see if it improves the score.如果上述方法都不起作用,我会尝试在<p>的高度上播放,看看它是否会提高分数。

I guess that Gatsby (and also Google) are working on adjusting this new feature and fix this bad score issues.我猜盖茨比(以及谷歌)正在努力调整这个新功能并解决这个糟糕的分数问题。

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

相关问题 graphql 标签中不允许字符串插值。 (盖茨比) - String interpolation is not allowed in graphql tag. (Gatsby) 为什么React会警告“ Unknown prop`p`” <p> 标签。 从元素中删除该道具。”如果没有这样的道具? - Why does React warn “Unknown prop `p` on <p> tag. Remove this prop from the element.” when there's no such prop? 在 React 构建中减少 Lighthouse “第一个有意义的油漆” - Reduce Lighthouse “First Meaningful Paint” in React build 使用 Gatsby 中的链接标签将样式注入 DOM - inject style into DOM using link tag in Gatsby 使用头盔向 Gatsby 添加脚本标签会引发语法错误 - Adding script tag to Gatsby using helmet throws syntax errors 警告:&lt;&gt; 标签上的未知道具。 从元素中移除这个道具 - Warning: Unknown prop on <> tag. Remove this prop from the element 在 `select` 标签中不起作用 `onChange` 和 `setState`。 (多个)在反应中 - not work `onChange` and not work `setState` in `select` tag. (multiple) in react 未知道具“可选”开启 <table> 标签。 在Material UI中 - Unknown prop `selectable` on <table> tag. in Material UI ReactJS - 标签上的未知道具`activeClassName` <a>。</a> <a>从元素中移除这个道具</a> - ReactJS - Unknown prop `activeClassName` on <a> tag. Remove this prop from the element JSX 没有相应的结束标记。 ts(17014) - JSX has no corresponding closing tag. ts(17014)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM