Make the web fast again

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.
No comments yet. Be the first to comment.
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...

As some of you loyal readers might know, I'm a big fan of optimizing the web.
As mentioned in the article, it's a never-ending battle. And when I decided to switch my website from Eleventy to Astro, I knew this battle would start again.
While rebuilding my website, I took speed into account and optimized the HTML structure.
With the redesign, I focussed on only using the bare minimum, meaning no useless divs, span, and classnames that wouldn't be used.
As well as using semantic HTML elements that help define the correct website structure.
Let's run a lighthouse test to see how it's performing as a baseline.
Note: It's essential to run the lighthouse test incognito as plugins and cache might affect it
First up is the mobile view.

98 on performance and 100 on accessibility, best practices, and SEO.
You always have to take these scores with a grain of salt. 100 doesn't mean it's perfect. It's simply that your technical test succeeds. You should always opt to do more tests and evaluate other criteria manually.
However, not a bad start!
We can see that we have three points of improvement:
Before fixing these, let's run our test on the desktop variant.

Here we even get 99 on performance and 100 on the other ones. That's an excellent start.
We can see the same three points of improvement.
Everything has to do with the images on the website. So what's wrong with them?
JPG formatSo what can we do to fix this?
We could change the format and serve a different format. However, we always need a fallback. I don't have the resources to host multiple variants of each image.
Then the sizing brings us back to the same issue. I can't host multiple sizes and render them back on demand.
I can, however, remove the encoding by using free software. Some examples are Imgoptim or an online tool like: exif remover.
All of this screams to use of an image delivery service. They can provide multiple formats on the fly and sizes and even remove the encoding.
There are numerous options, but I decided to go with Cloudflare images.
My main reason behind choosing Cloudflare is that I'm super happy with their page setup and wanted to see how easy the images tool is.
It's a super easy interface. You can drag and drop images, create multiple free transformations and choose what should be removed from the images.

That's pretty cool! And to top it off, we don't need to specify the formats we want. Cloudflare can determine the best format for a user based on their request! 🤯
To start, I only focussed on the eight images on the homepage. I upload them to Cloudflare and make one variant to begin with.
This was the public size, and I set it to be two times the desktop size to support retina screens.
My images are shown in 368x193, so the size I convert to is 736x385.
I then changed the image URLs to the Cloudflare ones and re-ran the tests.
The first test was on mobile again.

Almost there! We improved the score by one point and only have one item left to work on:
Now let's test the desktop variant and see what happens:

We did it, 100 points and no items left.
You might wonder, why is the mobile version not perfect? And the answer is, you can even see it in the image above.
I render the images in square sizes on mobile, but we still serve them in the desktop size. So to fix this, we need to add some more variants and switch them based on a media query. More on that in the following article.
Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on Facebook or Twitter