Largest Contentful Paint, or LCP, is a measurement of how fast your pages load. But it has even more significance: it impacts not only your user experience (namely: bounce rate), but also SEO
It can be hard to optimize without a bit of guidance, so I hope the below tips help you out:
How LCP is measured
First, how exactly is LCP measured. From web.dev:
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
Use a CDN and pregeneration
As much as possible, serve all pages and content pregenerated from a CDN cache. This ensures that response times are fast, and content can be visible as quickly as possible
Learn more: https://web.dev/optimize-lcp/#route-users-to-a-nearby-cdn
Preconnect to important origins
Preconnect to external domains to establish early connections to important origins using
Learn more: https://web.dev/uses-rel-preconnect/
Optimize your images
Importantly - be sure to optimize and prioritize your images. Use nextgen formats, optimal sizing, and eager prioritize your LCP image and lazy load others
This thread goes into great detail on recommended image optimization best practices:
Steve SewellPerformance is hard, and there are many things to know
That's why I have compiled many tips for image perf into this one cheat sheet!
More info in 🧵:14:48 PM - 22 Mar 2022
Remove blocking JS
It's 2022, there is no good reason to use blocking JS anymore. Make sure to load all JS asynchronously, or even better, in a worker with Partytown
Remove blocking CSS
Similarly, as much as possible, remove blocking externally fetched CSS.
CSS-in-JS libraries like styled-components or emotion can help a lot with this, or tools that can extract and inline critical CSS.
Learn more: https://web.dev/extract-critical-css/
Reduce JS execution
JS execution time can really hurt your LCP time as well. Be sure to optimize your site or app to require as little JS as possible to boot up.
Some projects that can help automate this for you include Qwik, Partytown, Marko, and Astro
Use API-driven services
Then, no site is complete without ways of managing and optimizing content. As much as possible, prefer API driven services for best performance, as opposed to those that require in-browser JS.
Some great services for managing content, assets, and tests include Builder.io, Cloudinary, LaunchDarkly, and Contentful
Measure, measure, measure!
Be sure to measure your LCP on real world emulate devices (read: not your powerful desktop computer!). Some great tools for this
- Builder.io performance insights - can tell you what can have the most impact to improve
- Google Pagespeed Insights - can give a lot of great granular suggestions
- WebPageTest - can let you dive deep into your performance from a wide variety of devices, browsers, and locations
To explore more about optimizing your LCP - this is a great post going into more detail on many of the topics mentioned above!
PS - this post was inspired by this great tweet from Filip Rakowski, go follow him!
Top comments (4)
The speed of my site was most affected by the connection of the CDN. G-core just speeded up my site and lowered my bounce rate. Strangely, some people continue to ignore the CDN to this day, and this is such a cool option to speed up the site.
I agree, it is strange to underestimate the impact from the CDN. Do you use free CDN or pay?
At first I tried the free one, which is quite good, by the way, with free SSL and anti-ddos. As I realized that this is a good product, I connected a paid plan. The price is nice.
Appreciate the WebPageTest mention re: LCP. There are so many ways to optimize the LCP, and I can point to ways that it can actually get hammered, and how you can insure bad Core Web Vitals and Lighthouse scores. Two yrs in a row, I've had presentations on LCP and images. Both were part of an extremely insightful annual event called Image Ready:
This Is Your LCP On Images by Patrick Hulce in 2020
Images And LCP by Tim Kadlec in 2021