Optimizing the PageSpeed results - part 17

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.
A while ago I did the series on the Next portfolio, and one of the people following along the series asked me how to filter by category. This is a great question and something I didn't dive into during the series. So here is a follow up on how to ac...
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 probably thought that was right. The portfolio is done and dusted. But now that it's live, we have to ensure people visiting our website have the best possible experience.
So in today's article, we will conduct a PageSpeed exam and address any issues we find.
You can use this fantastic website powered by Google to perform a basic report for your website.
Visit the PageSpeed Insights website
Fill out the URL to your website and click the "Analyze" button.
For my portfolio, I got the following results on mobile.

I'll be honest with you. We did well out of the box. We score 100 on Desktop and 89 on mobile.
Both have the same remarks. Our images can be optimized!
So let's tackle that issue and see what effect it has.
You might have noticed I used the project's default HTML <img /> tags.
There is an alternative we can (and should) use in Next.js, which is their wrapper called <Image />.
This component ensures all required props are set and will do some magic caching and sizing for us.
Let's open the project and open up the introHeader.js file and start by importing the next/image package like this:
import Image from 'next/image';
Then modify the image to use the new tag.
<Image
src='/profile.png'
width='240'
height='240'
alt='Image of Chris'
className='z-10 relative rounded-full'
/>
Yep, as easy as that, and our image will now be as optimal as possible.
The other image we use is actually on the work component.
So again, open up the work.js component and load the next image lib.
import Image from 'next/image';
This one is slightly different from before we had the image in the root. The image is also responsive, making it a bit more complicated with Next/image. So I added a wrapping div with the styling like this.
<div className='w-full md:w-1/3 mb-3 md:mr-6'>
<Image
src={item.image}
className='rounded-lg'
layout='responsive'
width={500}
height={335}
/>
</div>
You can also see we set the layout to be responsive, which ensures that the image scales nicely on mobile.
However, if we now run our application, we quickly see a Next.js error that the placedog.net domain is not a valid source for images.
This is because it's a strict setup, and we must set our website to allow this domain explicitly.
Open up the next.config.js file and add the images prop like this.
const nextConfig = {
images: {
domains: ['placedog.net'],
},
};
And now our images will load perfectly!
Let's deploy our changes and re-run the PageSpeed test.

Wow! We also got a 100 score on mobile now, and all the recommendations are gone.
Well done to us. Our users will also be happy to get a faster and more optimized website.
If you want to check out the changes, view this GitHub branch.
Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on Facebook or Twitter