How to Optimize Images for Web and Performance
Optimizing your website images is an important step for any designer, website owner, or webmaster. Keeping your website images optimized not only reduces the overall footprint of your website, it may significantly improve pagespeed and even make backups (or migrations) easier to complete. To better optimize your WordPress site images, you must first understand the differences of JPG vs. PNG image formats, why you should resize images, and why you should check file sizes. Make sure you understand the underlying logic for each component and be wary of over-optimizing (yes, image over-optimization is a thing unfortunately!)
Proper Image Formats:
- JPG/JPEG file types are best for photos of real people or real objects. They are prone to corruption or “noise” which becomes apparent when JPGs are “over optimized,” which we will get to later. JPGs do not support transparency.
- PNG file types are best for graphics and artificially designed artwork, such as logos, icons, infographics, etc. These are not prone to corruption the same way JPG images are, but they are way less efficient when used for “organic” photos of people, places, or objects. PNGs allow transparency.
Proper Image Resizing:
- Recommended background image dimensions are 1280×853 or 1280×720 depending on the aspect ratio. These numbers don’t have to be exact, but are more of a rule of thumb.
- Background images do not need to be bigger than 1920×1280 pixels, unless a significant portion of your customers use 4K displays (and if your website is actually built to support such a large screen).
- On page images that take up 50% screen width (i.e. a product photo sitting in one column) or less should not be wider than 640px.
Proper File Resizing:
- Don’t ever upload a huge raw or DSLR quality image and use WordPress or CSS to shrink it down to fit. The huge image is still being loaded, and either WordPress or the visitor’s browser has to work harder to resize the image right there on the spot.
- Tools like TinyPNG, EWWW Image Optimizer, and WP Smush strike the best balance between file size and image quality, by removing junk data, metadata, and extra color data from image files.
- Ideal file sizes for a 1920×1280 background image should be <500KB.
- A 1280×853 background image should be 90-250KB.
- These are ballpark estimates, but if you have a medium-sized product photo that takes up 800KB of space for example, you’re doing something wrong.
- For pagespeed purposes, you should never place an image more than 1MB on a web page. After all, you’re just adding more time for the page to load.
Dangers of Over-Optimizing:
- Yes, over-optimization (overzealous compression) should be avoided, or your images will look like dog excrement.
- EWWW and TinyPNG offer “lossless” optimization at their default modes, preventing this from happening. 99.9% of the time, lossless optimizing makes a huge positive difference in file size/pagespeed, without the human eye being able to tell.
- Don’t tweak compression settings unless you know what they mean & know what you’re doing.
- Google’s Pagespeed Insights offers “optimized resources” at the bottom of their test page and they are often ruined. Take Google’s (or any other tester’s) image size recommendations with plenty of salt.