How WebP images can speed up your (WordPress) site

WebP Images Logo

So you’ve been a brave admin of your website, minified and compacted the JavaScript and CSS, optimized all your images in order to make them as light as possible, and took proper care to have properly sized images or thumbnails loaded everywhere. If you have a WordPress site, using some plugins like Autoptimize or ShortPixel Image Optimizer saved you a lot of hassle in doing that. Now that’s great but what can you do next?

Enter WebP – a modern image format created by Google, that provides superior lossless and lossy compression for images on the web.

According to Google, WebP lossless images are 26% smaller in size compared to PNGs. WebP lossy images are 25-34% smaller than comparable JPEG images at equivalent SSIM quality index. Lossless WebP supports transparency (also known as alpha channel) at a cost of just 22% additional bytes. For cases when lossy RGB compression is acceptable, lossy WebP also supports transparency, typically providing 3 times smaller file sizes compared to PNG – that’s a huge improvement.

Now, how can you leverage this new format to improve the performance of your website?

Creating WebP versions of the images

If you have a WordPress website, you are lucky, there is a simple solution:

Starting with our 4.1 version of the ShortPixel Image Optimization plugin, we added the possibility to also create a WebP image alongside the existing images when optimizing your images with our service. Just enable the option in the Advanced tab of the ShortPixel settings, in your site’s admin and the WebP images will be created too when optimizing images.

The WebP versions of the images are only generated when the images are optimized. So if you need to add the WebP versions of the images after you optimized the images, the easiest way would be to:

  1. – Restore the images to their originals
  2. – Check the option “Also create WebP versions of the images”
  3. – Relaunch the bulk optimization.

Note: Starting May 10th 2021, the generation of WebP files will cost 1 credit per .webp file. For more information, please consult this article.

Using the WebP images

Direct solutions

Starting with version 4.12.2, you’ll be able to display WebP versions of the images in your WordPress website’s pages:

  1. Without altering the page code (via .htaccess)
    Checking the “Without altering the page code (via .htaccess)” option will insert a new block of code into the .htaccess file, which will make sure that: A. your browser supports WebP images and B. if you have both jpg/png and WebP versions of an image, then the server returns the WebP instead of the jpg/png. This has the benefit of serving directly WebP files without altering any of the page code.
  2. Altering the page code.
    Now you can use the WebP format by simply checking the corresponding “Using the <PICTURE> tag syntax” option in the advanced settings tab of Short Pixel and all your <img> tags will be replaced with <picture> tags that include also the .webp images, thus letting the browser chose the best version according to its capabilities. The <picture> tag contains also a Generate WebP markup tag for fallback reasons, thus also allowing the styles to remain in place. In some rare cases – when the styling of your images relies on positional queries ( :first, :nth-child selectors or “>” direct child reference ) you might encounter style problems when activating this option and you will need to use the cache plugin solution below. Note: The second option can be implemented either by hooking onto WordPress’s own functions (a more limited, but a bit safer method) or by simply analyzing all the code in a page and operating the needed changes before serving the page to the browser (this ensures more independence from any third party tools that might not operate through the official WordPress channels and methods)

Cache plugin solution:  You can also use a cache plugin that is WebP aware. We’ve tested the Cache Enabler plugin and it works out of the box with ShortPixel in delivering the WebP images. You just need to install and activate it, then go to Settings -> Cache Enabler and check the “Create an additional cached version for WebP image support” option.

cache-enabler-webp

That’s all, you can now enjoy a faster site that smartly uses WebP images!

UPDATE: Now the LiteSpeed Cache plugin is supported too! For this you need to do two things:

1. Add this constant in wp-config.php:

define('SHORTPIXEL_USE_DOUBLE_WEBP_EXTENSION', true);

2. Activate the LiteSpeed’s Advanced settings:

3. Activate the WebP delivery options:

4. Do not activate LiteSpeed’s option to generate the WebP files – ShortPixel will generate them when optimizing the images (If you already have optimized images, you will need to do a Media Library Restore and then run the bulk again).

32 thoughts on “How WebP images can speed up your (WordPress) site

  1. I have cometcache PRO plugin. Don’t think there is an option for this. I don’t want to enable this new setting till I know it’ll work with this caching plugin. Please let us know If it’s ok to enable this new format with the cometcache PRO plugin installed. I’d love to use this new feature.

    1. Now, how can you leverage this new format to improve the performance of your website? Please note that you currently can’t just replace the JPGs, GIFs or PNGs with their WebP counterparts as not all the browsers support it yet. But if you have a WordPress website, you are lucky, there is a simple solution: https://img.clippp.com/4c39adb7c21d57501af6ed736daa6f70_classroom-clipart-black-and-white-clipart-panda-free-clipart-classroom-clipart_324-324.jpeg

    1. Hi Derek,

      Sorry for my slow reply, somehow the alerts for comments on this post were not arriving to my inbox. As of now, Comet Cache does not support WebP, as far as I can see. So if the cache is not able to use the WebP images, it doesn’t make sense to activate the option in the ShortPixel Plugin.

      Regards,
      Simon.

    1. Hi,
      there are different ways but if you could share with me your site I could have a look and tell you how I checked.

      Thanks,
      Alex

        1. Thanks for the link, I tried to access it but the site seems to be down.
          Could you please check and let me know when I should try again?

          1. Well, there seems to be a country based firewall restriction, I cannot access it from Romania, any chance to change the restrictions?

  2. Why Cache Enabler page mentioned not compatible with ShortPixel? It stated: “Convert your images to WebP with Optimus.” And whether that means working ShortPixel possible only with the specified plugin cache Cache Enabler? What about those who have installed other plugins Super Cache, W3 Total Cache? You can read more will explain the situation using caching plugins together with ShortPixel (on the use of image expansion options WEBP). I am as hundreds of people are unclear about whether abandons conventional caching plugins in favor Cache Enabler, which would be able to use WEBP image on your site or are alternatives?

    1. Hello,

      Cache Enabler has WebP support. This means it’s taking into consideration the .webp images found and generates different cache files with src’s containing the found .webp images. Then, the specific cached files are served to Chromium browsers, instead of the regular ones.
      Any other cache plugin that does that would do the job just fine. You need to look into the cache plugin specifications and see if it mentions that it has WebP support and then it should work. So far we investigated some other cache plugins as Comet Cache or the ones that you mention, but they currently do not offer this feature.
      Regarding the fact that Cache Enabler mentions Optimus – I would say that this is because it’s from the same author. 🙂 But we tested it and it works flawlessly with ShortPixel.

      Regards,
      The ShortPixel team.

  3. Just a quick question:
    How do I check if the WebP images are working? I’ve tried downloading them and they download as png/jpg.
    Our site is: grabamile.boardingarea.com

    1. A quick way to do it is to use a WebP aware browser (e.g. Chrome) and check that the images loaded there are WebP instead of -let’s say- JPEGs.
      On your site I did a quick test and from what I see the results are mixed: some of the images are JPEGs and some are WebPs.

  4. If I already have uploaded images and they have been optimized by ShortPixel, what happens if I check the webp checkbox? Will re-optimizing the images create the webp versions?

    1. Hi,
      the way to have ShortPixel generate the WebP files if you already optimized all the images is like this:

      1) change your current optimization setting to Lossy/Lossless to Lossless/Lossy. Make sure you select WebP to be created
      2) Re-run Bulk ShortPixel
      3) when done, change back the optimization setting
      4) Re-run Bulk ShortPixel

      I realize that this is a bit cumbersome but, currently, it is the only way to do it.

      If you need further assistance please contact us directly here:
      http://shortpixel.com/contact

      Thank you! 🙂

      1. Just to clarify, if I change it to lossless and then back again to lossy, will that use up my credits for each conversion step? Basically, would require 3x as many credits: initial optimization, lossless optimization, then back to lossless optimization.

        1. It depends. If you don’t have many pics (say hundreds) and the optimization can be done as lossless and then back as lossy within an hour then you only be charged once. Also please note that we do not charge anything if we cannot optimize an image by at least 5%.

  5. I’m using Cache Enabler and ShortPixel, I’ve turned on webp within ShortPixel and have verified that webp images have been created, and I’ve followed the steps in this blog. However, when browsing my website on an up-to-date version of Chrome, all images are loaded as either gif or png. Any ideas on what’s going wrong? I’ve tried manually clearing the cache, but no luck. Thank you.

  6. Hi, I used and even paid for Shortpixel to compress all my images with webp enabled. (I chose glossy). However using Cache enabler in the way you described, just a few images are webp . How can that ratio be increased? My site is malimo.co (Malimo)

    1. Hi, sorry for the slow reply!

      As far as we tested it, it works only with Cache Enabler, being
      the only cache that has the WebP feature so far. This is the
      reason we developed the checkbox to replace tags with
      tags, in order to provide an alternative to those
      users that use a different cache plugin.

  7. I see WebP is only supported in certain browsers… Does the images automatically revert to the original format if WebP is not supported? Thanks

    1. Yes Nathan, WebP is only served on the browsers that support it, on the rest the original (JPEG or PNG) version of the file will be served.

  8. I have enabled wp. how can I check it. simplylifetips.com. wp super cache is installed. Can I use it cache enabler or should I remove super cache?

  9. Hi, I noticed that this does not appear to provide the WebP format for ‘Featured Images’ in wordpress… Is this a normal behaviour?

Leave a Reply

Your email address will not be published. Required fields are marked *