My Authors
Read all threads
🖼 If you’re building hero-style content with background images—maybe even through a CMS—you can hugely improve rendering times (LCP) with one additional line of HTML.
With the before, the browser won’t request the image until it knows it needs it—when the Render Tree is built. The problem is that the Render Tree can’t be built until the CSSOM is built, which means the browser needs to download and (re)calculate all applicable stylesheets.
Your Render Tree is only as fast as your slowest stylesheet.
This makes background images—much like fonts—late discovered resources. To get around it, you can make the request start much earlier by simply moving it to your markup. HTML is fast because its declarative nature means it can be preload-scanned.
The browser is smart enough to de-dupe the request, so there’s no penalty there. So now, even before the Render Tree is constructed, the browser is able to discover and request the image nice and early.
Now, by the time the Render Tree is ready and the browser is ready to display the page, the image should be partially, if not completely, over the wire. Before, it hadn’t even discovered the image until this point—much slower.
Of course, all of the above could be done with preload instead, but that will only work if you have access to the HEAD at the time your application is building the hero component.
For those saying ‘just use object-fit’: Absolutely! If:

1) …you want to (I’m not the boss);
2) …you have time for the slightly larger refactor;
3) …you’re happy to begin absolutely positioning some or all of your content.
Missing some Tweet in this thread? You can try to force a refresh.

Keep Current with Harry Roberts

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!

Twitter may remove this content at anytime, convert it as a PDF, save and print for later use!

Try unrolling a thread yourself!

how to unroll video

1) Follow Thread Reader App on Twitter so you can easily mention us!

2) Go to a Twitter thread (series of Tweets by the same owner) and mention us with a keyword "unroll" @threadreaderapp unroll

You can practice here first or read more on our help page!

Follow Us on Twitter!

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.00/month or $30.00/year) and get exclusive features!

Become Premium

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

Donate via Paypal Become our Patreon

Thank you for your support!