I made my website 28ms faster with content-visibility 🤓

I'm a full-stack developer from South Africa 🇿🇦. I love writing about JavaScript, HTML and CSS.
Search for a command to run...

I'm a full-stack developer from South Africa 🇿🇦. I love writing about JavaScript, HTML and CSS.
Thanks Tapas, Glad you liked it! 🔥
Your welcome, glad you like it
Wow Vamsi, This is so cool to read, thank you!
I am actually planning on writing that, but kind of finding a good structure for it.
I'm close to 200 articles, and likely it will be somewhere around there.
Most of you know me for my consistency, a golden arrow in my blog series. I've written 1000 articles in 1008 days! Almost an article a day, and my honeymoon was the only holiday I ever took. I'm super proud of this achievement; it has been a fantasti...

It's not the first time I'll be talking about community. I think it's an essential aspect of any successful tool. This shows in my previous explorations of Astro, Medusa, and now Vendure as well. All these products thrive in a super open, welcoming, ...

The cool part about Vendure is how easy it is to set up and how abstract each layer is. Basically, we get the following elements: External database Server Worker Admin UI Frontend While this is amazing, it also brings a bit of complexity when it co...

The previous article looked at customizing Vendure on a data and process level. In this article, we'll look at customizing emails, as they are often a big part of a webshop system. We'll be looking at two different layers of customization for customi...

Even though Vendure is a pretty significant project out of the box, in some cases, we might want to go in and modify some elements to work to our specific use case. In this article, I'll take a high-level look at some elements we can customize within...

You might think, what is 28ms? If you are a big advocate of speeding up the web and getting perfect scores on Eleventy's speedlify dashboard, it's a lot!
Not that I was doing bad, as you can see in the screenshot below. I just wanted to get full 100's and get the full potential out of my website.

I read about this CSS property a while ago. But never got round to implementing and testing it. That is until today, so let's see what it actually does.
The content-visibility has three values we can use:
visible (no effect, basically how it was before)hidden (a mix between display: none and visibility: hidden, it starts on display hidden, afterwords becomes visibility hidden)auto (This is the one we are looking at. It will only render this element once the browser needs it!)So how can we add it to elements?
.element {
content-visibility: auto;
}
I've added this on my homepage to the article-list and footer elements.
To give you a better understanding, I did a lighthouse test before these changes.

But more important is the actual trace where we can check the total time.

And then, after adding the content-visibility to those two elements, I've rerun the test.

And the trace:

That means it was 443ms and is now 415ms, which means + 28ms win!
Conclusion: There is no downside to not adding the auto one. It can only benefit your website, even the small numbers matter.
I even added my content-visibility on the post pages, where the main content is set to auto.
The following screenshot is a before rendering:

And this is the after rendering:

As you can see, it improved my score overall.
And adding content-visibility made the Time to Interactive 1.1s faster.
Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on Facebook or Twitter