Optimizing your largest contentful paint (LCP) can be hard
Here are 8 tips, with code snippets and visuals, to help your pages load fast for optimal SEO and UX
🧵👇
First, how is LCP measured?
> 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
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
Importantly - be sure to optimize and prioritize your images. Use nextgen formats, optimal sizing, and eager prioritize your LCP image and lazy load others:
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 web.dev/extract-critic…
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.
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
Want to measure your LCP and see which tip above might help improve it the most?
Oh ya! And don't forget to measure measure measure your site speed. Prefer tools that emulate real world devices like @RealWebPageTest and Google Pagespeed Insights over running Lighthouse in your desktop browser that may not match typical real world device specs
LLMs are bad at acknowledging what they don't know
But they are good at answering questions from a well defined context
So instead, you can provide a set of information via RAG (retrieve it and supply it in the prompt) and tell the LLM to *only* answer questions from this data
Don't be that teammate who blindly refactors code and only makes things worse.
Let's look at some good vs bad refactoring patterns with real examples 🧵
Let's take this code.
I hired a developer once that saw us calling this `functions.runWith(...)` repeatedly with different options and decided to consolidate it all into one createApi function
This new, consolidated code, had a huge issue.
Can you see it?
When we started deploying these APIs, they began breaking left and right.
In all seriousness though, I know I post a lot of coding tips and "do this not that" best practices stuff, but I want to use this as a reminder to point out...
I don't write perfect code. No one does. My code has been complained about by fellow engineers as much as anyone, if not probably more.