Recommendations

Lighthouse
Metrics
Audits
PageSpeed (Legacy)
YSlow (Legacy)

PageSpeed: Optimize images

Overview

Reduce the load times of pages by loading appropriately sized images.

  • Reduce file sizes based on where images will be displayed
  • Resize image files themeselves instead of via CSS
  • Save files in appropriate format depending on usage
  • Cost benefit ratio: high value
  • Access needed
How does your site score on this recommendation?

What is optimizing images for the web?

The images you create in programs like Photoshop and Illustrator look amazing but often the file sizes are very large. This is because the images are made in a format which makes them easier to manipulate in different ways.

With file sizes upwards of a couple of megabytes per image, if you put these files on your website it would be very slow to load.

Optimizing your images for the web means saving or compiling your images in a web friendly format depending on what the image contains.

Images hold data other than just the pixels we see on the screen. This data can add unnecessary size to the image which leads to longer load times as the user waits for the image to download.

In terms of cost versus benefit optimizing your images should be near the top of your page speed optimizations if you don't have them optimized already.

How does it work?

In simple terms optimizing your image works by removing all the unnecessary data that is saved within the image to reduce the file size of the image based on where it is being used in your website.

Optimizing images for the web can reduce your total page load size by up to 80%.

There are two forms of compression that we need to understand, Lossy and Lossless.

Images saved in a lossy format will look slightly different than the original image when uncompressed. Keep in mind that this is only visible at a very close look. Lossy compression is good for web, because images use small amount of memory, but can be sufficiently like the original image.

Images saved in lossless format retain all the information needed to produce the original image. For this reason these images carry a lot more data and in return are a much large file size.

We also can optimize images for the web by saving them as the appropriate dimensions. Resizing the image on the webpage itself using CSS is helpful but the issue is the web browser will still download the entire original file, then resize it and display it.

Can you imagine take a poster size image and using it as a thumbnail? The little 20px by 20px image would take as long to load as the original poster, when we could just be loading a 20px image the whole time.

Why is it important?

The main reason why it's so important to optimize your images is because 90% of most websites are graphics dependent and therefore there are a lot of image files. Leaving these images uncompressed and in the wrong format can drastically slow down your web page load times.

How to Optimize Your Images

Full optimization of images can be quite an art to perfect as there are such a wide variety of images you might be dealing with. Here are the most common ways to optimize your images for the web.

  • Reduce the white space around images - some developers use whitespace for padding which is a big no no. Crop your images to remove any whitespace around the image and use CSS to provide padding.
  • Use proper file formats. If you have icons, bullets or any graphics that don't have too many colours use a format such as GIF and save the file with lower amounts of colours. If you have more detailed graphics then use JPG file format to save your images and reduce the quality.
  • Save your images in the proper dimensions. If you are having to use HTML or CSS to resize your images, stop right there. Save the image in the desired size to reduce the file size.

To resize your images you will have to use some form of program. For basic compression you can use a simple editing program such as GIMP. For more advanced optimization you will have to save specific files in Photoshop, Illustrator or Fireworks.

Read our Lighthouse documentation to learn more about optimizing images.

Which tools does PageSpeed use to test this recommendation?

For JPEGs: libjpeg-turbo, and for PNG/GIFs: OptiPNG.

Summary

Images
High
Moderate
71%

PageSpeed recommends:

Choose an appropriate image file format

The type of an image can have a drastic impact on the file size. Use these guidelines:

  • Use JPEGs for all photographic-style images.
  • Never use BMPs or TIFFs.
  • For graphics, PNGs are almost always superior to GIFs. IE 4.0b1+, Mac IE 5.0+, Opera 3.51+ and Netscape 4.04+ as well as all versions of Safari and Firefox fully support PNG, including transparency. IE versions 4 to 6 don't support alpha channel transparency (partial transparency) but they support 256-color-or-less PNGs with 1-bit transparency (the same that is supported for GIFs). IE 7 and 8 support alpha transparent PNGs except when an alpha opacity filter is applied to the element. You can generate or convert suitable PNGs with GIMP by using "Indexed" rather than "RGB" mode. If you must maintain compatibility with 3.x-level browsers, serve an alternate GIF to those browsers.
  • Use GIFs for very small or simple graphics (e.g. less than 10x10 pixels, or a color palette of less than 3 colors) and for images which contain animation. If you think an image might compress better as a GIF, try it as a PNG and a GIF and pick the smaller.
Use an image compressor

Several tools are available that perform further, lossless compression on JPEG and PNG files, with no effect on image quality. For JPEG, we recommend jpegtran or jpegoptim (available on Linux only; run with the --strip-all option). For PNG, we recommend OptiPNG or PNGOUT.

Read More

Cookie Policy

By clicking "Allow All" you agree to the storing of cookies on your device to enhance site navigation, analyze site usage, and assist in our marketing efforts. View cookie details

Deny Allow All
×