How we improved the performance of an E-commerce site using Next-Gen image formats?
Tags: imagecompression, webp, websitedevelopment, websiteperformance
Published: 2020-04-27 06:13:27

---
title: How we improved the performance of an E-commerce site using Next-Gen image formats?
published: true
date: 2020-04-03 11:47:28 UTC
tags: image-compression,webp,website-development,website-performance
canonical_url: https://medium.com/commutatus/how-we-improved-the-performance-of-an-e-commerce-site-using-next-gen-image-formats-8bcff1bf5b19
---

### How did we improve the performance of an E-commerce site using Next-Gen image formats?

E-Commerce is a growing industry that offers convenience to shop online. According to research, visual content is the best way to give users the same experience online as they get it in-store. However, the better the visual content, the larger the page size is going to be and this, in turn, affects the website’s load time. This decrease in website performance could result in losing out on a lot of potential shoppers. So how can we ensure high-resolution image delivery without hurting the performance of the website? Read on to know more.

![How we boosted Performance of gehna website by using webp image format](https://cdn-images-1.medium.com/max/1024/1*s3TjvmSpKaWrXtVlKrhY1g.png)<figcaption>Improving website performance using WebP image format</figcaption>

### How to serve images without compromising the site performance?

With the advancement in web technologies, we now have a few [Next-Gen image formats](https://developers.google.com/web/tools/lighthouse/audits/webp) that have better compression and quality characteristics compared to their older JPEG and PNG counterparts. Serving your images in these formats will load websites faster and consume less bandwidth. Here is the list of next-gen image formats currently available:

- WebP
- JPEG 2000
- JPEG XR

### Why did we choose WebP?

WebP is a new format that was developed by Google in 2010 to provide improved lossless and lossy compression for images. A major benefit of using WebP images is their reduced size and according to Google on average WebP images are 30% smaller in size compared to PNGs and JPEGs. If you look at the total payload of web pages, the images on most sites account for over half of that payload. So by using WebP images with up to 30% size reduction in images, you will see a noticeable impact on your site’s performance metrics.

![JPG vs WebP size comparision](https://cdn-images-1.medium.com/max/1024/1*zV0QJod0ZW932c95h15M5w.png)<figcaption>JPG vs WebP</figcaption>

### Restraint we faced while implementing WebP

One of the major facts you need to be aware of WebP images is cross-browser support. Although about 79% of the global users surf using a browser that supports WebP, we still needed to serve JPG images to iOS and Mac users with Safari browser.

![Webp image format support by browsers](https://cdn-images-1.medium.com/max/1024/1*0E5Sfc7BnGOggYnby2dizA.png)<figcaption>WebP cross-browser support.</figcaption>

Now that you see the problem just as we did, you do not need to brainstorm ideas to find the apt solution. Here are two techniques I have discovered to overcome the problem -

- Make changes on the user-facing platform by using a <picture> tag to serve multiple versions of the same images.
- Use/Develop a service that optimizes and serves WebP images from a CDN cache, on-the-fly by detecting the user’s browser.

I would recommend using the second option as there no changes required on the application. Now, if you are interested in learning more about the service (AWS Lambda Function and CloudFront to serve WebP images) we developed, check our [technical guide here](https://awesome.commutatus.com/domains/engineering/efficient/cloudfront-image-conversion.html).

#### Why did we do it this way?

![Webp our solution to performance](https://cdn-images-1.medium.com/max/1024/0*DCgaTGffRYS2tpZg)<figcaption>Image optimization — our way.</figcaption>

There are a lot of services that offer image optimization on the fly but important things we had to keep in mind are:

- **Storage** : Most of the image optimization services out there require you to store the images in their databases and serve it from there. Since we already had over 20,000 high-resolution images in our AWS S3 bucket, we didn’t want to take the hassle of migrating it elsewhere.
- **Modifications** : We wanted to implement a solution that had the least alterations to our frontend and backend systems which means the existing code in both UI and API will continue to work.
- **Recurrent Costs** : With hundreds of visitors on the site every day, the price to pay for the bandwidth consumed from any optimization service is significantly higher. So we used our own function on AWS lambda@Edge and S3 to optimize the images at almost no additional costs.
- **Processing:** Converting the whole library of images into WebP format is again an arduous task and could take a lot of time. So, we only convert images into WebP on their first request. As an added bonus we also process and store different dimensions of the images in the cache to achieve instant delivery from edge locations.
- **Modularity** : Our solution can be easily deployed to any of our other platforms without the need for remodeling.

### Our results:

With, WebP efficiently compressing the images and preserving the quality and our edge functions caching the images we didn’t have to tradeoff between image quality or the number of images to serve to achieve faster load speed.

![images size in homepage of gehna website after using webp image format](https://cdn-images-1.medium.com/max/1024/1*erbper8cYxtjizadpIRkcQ.jpeg)<figcaption>Image formats size comparison.</figcaption>

Google has indicated that site speed is one of the signals used by its algorithm to[rank pages higher](https://dev.to/chandan/how-friendly-are-single-page-applications-to-seo-51d9-temp-slug-2597941). With the above techniques and improved performance, we were also able to obtain higher scores in page audits.

![Performance boost in google lighthouse audit of gehna website after using webp image format](https://cdn-images-1.medium.com/max/1024/1*hk_7uIvF1m9hCQ5h8sBVHA.png)<figcaption>Google Lighthouse — audit scores.</figcaption>

By serving the images from AWS Lambda@Edge, we were able to load [Gehna’s](https://www.gehnaindia.com) homepage in under 5 seconds.

![Decrease load time of website after using webp](https://cdn-images-1.medium.com/max/972/1*zDAIdagqSgyFmOteajefaA.png)<figcaption>Decreased load time of web page.</figcaption>

The below graph shows the improvement in page speed provided by GTmetrix.

![Performance boost website after using webp](https://cdn-images-1.medium.com/max/991/1*Pt7xSvIR7xlYZBvUJzZHvw.png)<figcaption>GTmetrix page speed after WebP images.</figcaption>

#### Wrapping up:

Next-gen image formats like WebP offer an incredible saving in file size with relatively little to zero compromises in image quality and when coupled with AWS Lambda@Edge, it provides great value in boosting the performance of a website. WebP definitely seems to be a promising image format for the web with anticipation of Apple’s Safari supporting WebP images in the near future.

Also, do check out the awesome E-commerce website [**Gehna**](https://www.gehnaindia.com) we built at [**Commutatus**](https://www.commutatus.com) using Next.JS.

![Gehna website built at commutatus](https://cdn-images-1.medium.com/max/1024/1*gF4YbRwzaZz2E0ysA1N8tg.jpeg)<figcaption>Gehna (E-commerce jewellery platform) built with ❤️ at Commutatus using Next.js</figcaption>

If you find this article useful in improving the performance of your web site, give an 👏 and leave a comment on — What other techniques can make your page load faster? I’d love to hear any thoughts on this topic 😋

* * *