Skip to content

Conversation

vincanger
Copy link
Collaborator

Description

Some minor image performance boosts

Contributor Checklist

Make sure to do the following steps if they are applicable to your PR:

@vincanger vincanger requested a review from Martinsos October 30, 2024 16:25
@vincanger vincanger marked this pull request as ready for review October 30, 2024 16:25
Copy link
Member

@Martinsos Martinsos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved, but asked some questions!

];

const NavLogo = () => <img className='h-8 w-8' src={logo} alt='Your SaaS App' />;
const NavLogo = () => <img className='h-8 w-8' src={logo} decoding='async' alt='Your SaaS App' />;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, article here claims there isn't much improvement normally https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/decoding , which suggests one should normally not bother with setting this value.

How have you decided it is worth setting it?

Copy link
Collaborator Author

@vincanger vincanger Oct 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you're right, after reading up on it it seems like it's more likely designed for swapping out a thumbnail with a large image once it's done loading, something we're not doing here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok! So we remove this one/

<figcaption className='mt-6 text-base text-white'>
<a href={testimonial.socialUrl} className='flex items-center gap-x-2'>
<img src={testimonial.avatarSrc} className='h-12 w-12 rounded-full' />
<img src={testimonial.avatarSrc} loading='lazy' decoding='async' className='h-12 w-12 rounded-full' />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a quick read about loading here: https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/loading .

It says that in Firefox it has to go before src to take effect. Silly requirement, but maybe let's make sure that happens? Maybe React does it for us, but likely it doesn't, and better not to rely on it.

Also, I am guessing we shouldn't be setting loading='lazy' for every image we have? Or should we? What is the strategy about it, how do we make decision what is loaded lazily and what eagerly? I read that one con of lazy loading is that things around image might need to move around if height and width are not known upfront.

Copy link
Collaborator Author

@vincanger vincanger Oct 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that for everything below the main fold, lazy should be fine. I also tested it on the main hero image, which is kind of below the fold, and I don't see any noticeable difference.

Concerning the other properties, that sounds good and I will move the loading and decoding properties to the start.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok soudns good!

@vincanger vincanger merged commit 3bb7865 into main Nov 12, 2024
@vincanger vincanger deleted the improve-lighthouse-score branch November 12, 2024 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants