How to optimize your LCP (with visuals!)
Steve Sewell
Posted on March 29, 2022
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 <link rel="preconnect">
:
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:
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
Learn more:
- https://web.dev/optimize-lcp/#render-blocking-resources
- https://web.dev/efficiently-load-third-party-javascript/
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
Next Steps
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!
Posted on March 29, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.