Image optimization is the process of reducing the file size of an image without sacrificing its quality. If your website is having performance issues, including slow page loading times, image optimization can help resolve your problems.ย
Hereโs an in-depth tutorial of the step-by-step process required to optimize website images. The process described below assumes that youโre not using a WordPress plugin for assistance.
#1 โ Prepare The Image and Make Sure Itโs Saved Properly
Even if youโre using an image optimizer or compression tool, there are a few things you need to do before running that image through compression.
First, make any necessary edits or enhancements to the image. Things like filters, cropping, contrast adjustments, exposure, saturation, and other edits should be handled before you proceed. You can continue using whatever image editing software youโre comfortable with for this step.
From here, itโs important that you save the image properly. For most website images, youโll have two main options to considerโPNG and JPEG.
- PNG Image Files โ PNG files are larger, but they support a wide range of colors. PNGs are also the only image file format that works with transparent backgrounds on a website. If youโre editing a photo multiple times, itโs in your best interest to export it as a PNG before uploading it to your website.
- JPEG Image Files โ JPEGs provide a good balance between quality and file size. This is the most common file format of digital cameras. JPEGs should work for the vast majority of images on your site, especially since the file format is smaller than a PNG.
Overall, PNGs work well for images that donโt have a ton of color. If an image has lots of lines, icons, or sharpness, PNG will be a better option as well. JPEG compression could create some contrast issues in this scenario.
A top benefit of using JPEG files is that youโll be able to choose the quality of the image before running it through a compression tool.
Hereโs an example using Preview, the default image viewer on a Mac:
If you export images as a JPEG file, you can adjust the quality by simply sliding the bar. By reducing the image quality, youโll simultaneously reduce the file size.ย
Unless youโre a professional photographer, JPEG quality around 40% to 50% should be fine for most of you. For example, if youโre uploading photographs to your portfolio of a clientโs wedding, itโs probably in your best interest to sacrifice file size for image quality.
In addition to the edits and choosing the right file format, youโll also need to prepare the correct image dimensions before proceeding to the next step.
Think about where and how the image will be used on your website. For example, the dimensions of an image used within a blog post will likely be different from an image icon on a product page.ย
If the content area on your blog is 700 pixels wide, the dimensions for an image here should never be larger than 700 pixels.ย
Any time youโre resizing an image, make sure you enable the option to scale the height and width proportionately. Otherwise, the image will get distorted.
Hereโs an example of a JPEG that was 2634 x 2718 pixels and 1.8 MB:
By changing the width to 700 pixels, the height automatically scaled to 722 pixels. This also reduces the file size.
Once youโve saved the image with the right file format and dimensions, you can continue to the next step.
#2 โ Run the Image Through a Compression Tool
Now itโs time for the image to get compressed. The easiest way to compress images is by using an online tool.ย
There are countless options to choose from. But for our purposes here today, weโre going to use TinyPNG.
Thousands of companies worldwide rely on TinyPNG for image compression. This includes big brands like Samsung, Walmart, Sony, Lego, and Bank of America. As previously mentioned, you can use this TinyPNG for free to optimize images for your website.
Start by navigating to the TinyPNG homepage. From here, you can simply drag and drop your image file into the box at the top of the screen.
The tool will automatically compress any image files that you upload without any extra steps or actions required on your end. Once the process is complete, just click the download button to retrieve your newly compressed image.
In the example above, TinyPNG took a JPEG file that was 534 KB and compressed it by 86%, reducing the file size to just 76 KB.
The original image that we started with prior to step one was a whopping 6 MB! This is a file that would be too large to compress using TinyPNGโs free service.ย
But after taking the time to save it as JPEG, adjust the quality, and change the dimensions, it set us up for success with the compression.
Now, letโs pretend we just changed the quality of the initial JPEG without adjusting the dimensions. If you refer back to step one, youโll see this reduced the file size to 1.8 MB (still significantly less than 6 MB).
If we run that file through TinyPNG, it gets compressed to 446 KBโnearly six times larger than our 76 KB file that we changed the dimensions for.ย ย
Thatโs why the preparation in the first step is so important. If you jump straight to the compression tool, youโre still leaving a lot on the table in terms of how much you can optimize the image.
The reason why we recommend TinyPNG so highly is because the difference in image quality is unnoticeable to the naked eye. Take a look at this example comparing two transparent PNGs before and after compression:
Do you notice any difference? Didnโt think so.ย
#3 โ Upload the Image to Your Website
This step will look a little different for everyone. It all depends on the CMS that youโre using to power your website.ย
WordPress users will have a different interface than Magento, Shopify, Drupal, Joomla, BigCommerce, etc. Since WordPress is the worldโs most popular CMS, and thatโs what we use to run our site here at Crazy Egg, weโll use it as the example for this step.
Navigate to Media on the left side of your WordPress dashboard. Then select Add New and either drag-and-drop the image or select a file from your computer.
Once an image has been added to your WordPress media library, itโs easy to insert it into blog posts or landing pages on your site. Alternatively, you can complete this process in real-time as youโre creating new content on your site.
For example, letโs say youโre writing a new blog post on WordPress. Writing the text then coming back and inserting images later may not work well for your process.
Since the image optimization process just takes a minute or two, you can go through the first two steps any time you reach a point in your blog post that calls for an image.
Then just click the Add Media button on the post and upload the image without leaving the blog.ย
If you feel like navigating away from the post to take care of the image optimization distracts your writing workflow, thatโs ok. Just donโt forget to add the images when you finish writing.ย
#4 โ Host Your Images on a CDN
Remember why weโre optimizing images in the first placeโweโre trying to improve page loading speed.ย
In addition to the image optimization itself, you can take this concept one step further by hosting your optimized website images on a CDN (content delivery network).
Rather than storing the images on your own servers, CDNs have networks strategically placed all over the world. So website visitors will get images delivered to their screen from a server thatโs closest to them, geographically speaking.ย
For example, letโs say your website servers are located in the United States. If a user in Europe lands on your site, the CDN can use a server thatโs located closer to that specific visitor, ultimately increasing the page loading speed.ย
Tinify CDN is TinyPNGโs content delivery network. So if youโre using TinyPNG to optimize your images, itโs only natural to consider them as your CDN provider as well.ย
While a CDN doesnโt replace your web hosting service, it can take a significant load off of your servers.
Tinify CDN starts at $15 per month. But that plan really only accommodates personal websites and small blogs.ย
Most of you should be signing up for the Business package, at a minimum. This plan starts at $69 per month, and you can try it free for 14 days.
#5 โ Use a Lazy Load Plugin (BONUS)
By now, youโve already optimized the images for your website. And while thereโs nothing you can do to optimize the image any further, there are still steps you can take to ensure your pages load as fast as possible.
Lazy loading plugins are your best option here.
The concept behind lazy loading is simple. Images that arenโt in the field of view arenโt loaded until a visitor gets closer to that part of the page.
So images at the bottom of your page wonโt load at the same time as an image above the fold. This tip will significantly increase your page loading speed, especially for pages with multiple images.ย
Examples of popular lazy load plugins include:
For those of you who want to take your website image optimization strategy to the next level, these plugins will get the job done.
Next Steps
Now that youโve mastered image optimization for your website, itโs time to focus on other ways to improve your website performance.
Check out our guide on the best ways to speed up your website and improve conversions. These tips go beyond basic image optimization.ย
You should also learn how to clear your cache in WordPress. This five-step guide is extremely helpful for WordPress beginners looking for ways to improve their site performance. Itโs especially useful for websites with lots of images.ย