Properly Sized Images in Lighthouse to speed up your website

Properly Sized Images in Lighthouse to speed up your website

Optimize your site's speed by learning how to properly size images with Google Lighthouse

Posted by Joe Dodds on May 27, 2023

Google Chrome's Lighthouse tool is a valuable resource for developers seeking to optimize their websites for performance, accessibility, and SEO. One of the key opportunities identified by Lighthouse is the need to "Properly size images". This aspect of the report, found under the Opportunities section, lists all images on your page that are not appropriately sized. By resizing these images, you can save data and significantly improve your page load times.

Understanding the Need for Proper Image Sizing

Many websites suffer from slow load times due to images that are larger than necessary. An oversized image takes longer to load and uses more data, which can be especially problematic for users on slower internet connections or mobile devices. Properly sizing images not only improves your website's speed but also enhances the user experience and can have a positive impact on your SEO.

Identifying Opportunities with Lighthouse

Lighthouse provides a detailed list of images that are not appropriately sized in the Opportunities section of the audit report. Each image is listed along with the potential savings in kilobytes (KB) that could be achieved by resizing it to better fit its display size.

The tool calculates this potential saving by comparing the current image size with its display size. The difference in KB represents the amount of data that can be saved and the corresponding improvement in load time.

Implementing the Changes

After identifying the images that need to be resized, the next step is to generate resized versions of these images. There are various tools available to accomplish this task. A popular one is:

  • Imagelato, an online tool that enables you to convert, resize, and optimize web images.

Once you've resized your images, ensure that they are correctly referenced in your HTML. This usually involves updating the 'src' attribute of the 'img' HTML element to point to the new, smaller image.

Using the Picture HTML Element

In addition to resizing images, you can further optimize your website by using the <picture> HTML element to specify alternative versions of an image. This tag allows you to provide different images based on various conditions such as viewport size and image format support. MDN's documentation provides an excellent guide to using the <picture> element.

For example, you can use the 'media' attribute to serve high-resolution images for displays with higher pixel density. You can also use the 'type' attribute to specify different formats such as WebP and JPEG. Here's how you might use the <picture> tag:

<picture> <source media="(-webkit-min-device-pixel-ratio: 2)" srcset="image-highres.webp" type="image/webp"> <source media="(-webkit-min-device-pixel-ratio: 2)" srcset="image-highres.jpg" type="image/jpeg"> <source srcset="image.webp" type="image/webp"> <source srcset="image.jpg" type="image/jpeg"> <img src="image.jpg" alt="Description"> </picture>

In this example, the browser will try to pick the best source based on its capabilities and the media conditions. CSS-Tricks provides further information about using the 'media' attribute with device-pixel-ratio.

Browser Compatibility and Responsive Design

While resizing your images, it's essential to consider browser compatibility and responsive design. Different devices and screen sizes will require different image sizes to look their best. Therefore, you should provide multiple versions of each image and use HTML and CSS features like the 'srcset' attribute or the 'picture' element to deliver the most appropriate image to each user.

For more information about responsive images and browser compatibility, Can I use is an excellent resource to check the support of different features across various browsers, and CSS Tricks guide on Responsive Images provides comprehensive details on the subject.

Conclusion

The "Properly size images" opportunity provided by Google's Lighthouse tool is a powerful way to identify potential performance improvements for your website. By resizing your images to match their display size, you can save data and significantly enhance your website's load times. Using the <picture> tag and considering browser compatibility further optimize your site. This simple optimization step can lead to a better user experience, improved SEO, and a more efficient web presence.

Imagelato helps you host and manage images in all formatsimagelato

Sign up for our newsletter

Recent articles