Search code examples
reactjsgatsbypagespeedlighthousepagespeed-insights

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


I don't know why my LCP would be a p tag, and I have no idea what I would do to reduce the size of it. Sometimes it gets up to 2.6s and gives a yellow rating(instead of green).

enter image description here

This is the p tag. 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

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


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.

    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.

    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/

    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. 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.

    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.

    So for clarity instead of:-

    • HTML requested, (200ms round trip to server)
    • HTML loaded and parsed, links to CSS and JS found required to render the initial page content
    • CSS and JS requested. (200ms round trip to server)
    • CSS and JS loaded
    • Enough to render the page.

    Instead you have

    • HTML requested, (200ms round trip to server)
    • HTML loaded, all required CSS and JS inlined in HTML
    • Enough to render the page

    This may not seem like a lot but that 200ms can make a huge difference to perceived speed.

    Also this is a simplified example, often a page requires 20 requests or more to render the above the fold content. 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.

    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. 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.