Steve Sewell Profile picture
Mar 29 15 tweets 8 min read
💡 Web performance tip

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

🧵👇 Image
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

web.dev/lcp/ Image
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

web.dev/optimize-lcp/#… Image
Preconnect to external domains to establish early connections to important origins

web.dev/uses-rel-preco… Image
Importantly - be sure to optimize and prioritize your images. Use nextgen formats, optimal sizing, and eager prioritize your LCP image and lazy load others:

Remove all blocking JS. Make sure to load all JS asynchronously, or even better, in a worker with Partytown

web.dev/optimize-lcp/#…
web.dev/efficiently-lo… Image
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… Image
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 @QwikDev, Partytown, @MarkoDevTeam, and @astrodotbuild Image
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 Image
Want to measure your LCP and see which tip above might help improve it the most?

This could help you out: builder.io/c/performance-…
Additionally, I want to give credit to @filrakowski that inspired this post via his fantastic tweet here. Go follow him!
Also, huge kudos to @hdjirdeh for his amazing article here that covers everything above and more: web.dev/optimize-lcp/
Services featured above: @builderio @cloudinary @LaunchDarkly @contentful
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
A few more great accounts to follow for learning about performance best practices: @jaffathecake @mgechev @addyosmani

Am I missing any? Lmk if so!

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Steve Sewell

Steve Sewell Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @Steve8708

Mar 30
Perf quiz!

What is the correct attribute for browser-native lazy loading?

Answer in 🧵👇 Image
The answer is 4! Did you get it right?

Learn more: web.dev/browser-level-… Image
PS - this attributes is now available in all major browsers!
Read 5 tweets
Mar 28
Performance tip: if you need to set a lot of dynamic keys to an object, a Map can give you better perf

Explanation in 🧵: Image
The answer has to do with monomorphism: mrale.ph/blog/2015/01/1…

In short, JS VMs try to assume a shape of an object using a hidden class. When the shape changes, this can lead to a deopt

It's the same reason why setting a property to null/undefined can be faster than deleting: Image
A Map, on the other hand, is optimized for this very use case of frequently adding and removing keys (see the "performance" table row here): developer.mozilla.org/en-US/docs/Web…
Read 7 tweets
Mar 22
Performance tip: did you know that even a simple chat widget can have a negative impact on your site performance?

But there is a solution: you can render a div that *looks* like the widget button, that on click downloads the actual widget JS only when needed

More info in 🧵:
We did this on the @builderio site to great success, and wouldn't have the performance score we have without it!
Note though: this method will not support all features of your chat widget platform.

If you want to use features like popping up messages to visitors automatically, you should use the standard embed code and pay the performance tax
Read 4 tweets
Mar 22
Performance 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 🧵:
Great deep dive for much more info here: web.dev/image-componen…
Now, you may be thinking "that is a lot of work!"

Well, you are in luck. Image components provided @cloudinary, @nextjs, @GatsbyJS, and @nuxt_js do many of these optimizations (like nextgen format, dynamic srcset, etc) for you completely automatically!
Read 9 tweets
Mar 21
Performance tip: make your page load feel more instant by using priority hints to help the browser prioritize the most critical resources

More you can do with priority hints in 🧵:
You can also prioritize iframes, scripts, links, and fetch!

Learn more: web.dev/priority-hints/
If you are wondering "between scripts, images, and iframes, which would have the most impact on my site speed to put time into optimizing" - I got you: builder.io/c/performance-…
Read 4 tweets
Mar 16
Performance tip: did you know you can make a fast function for relative time strings with ~30 lines of code and 0 dependencies?

Code in 🧵:
Steal the code, or let me know how to improve it!

Github gist: gist.github.com/steve8708/ada9…
The key here is Intl.RelativeTimeFormat

Read 7 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(