WordPress

How WebP images can speed up your (WordPress) site

Published on 29. April, 2021

How WebP images can speed up your (WordPress) site

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.

How WebP images can speed up your (WordPress) site Ursus Minor

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 tag syntax” option in the advanced settings tab of Short Pixel and all your tags will be replaced with tags that include also the .webp images, thus letting the browser chose the best version according to its capabilities. The 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:

How WebP images can speed up your (WordPress) site Ursus Minor

3. Activate the WebP delivery options:

How WebP images can speed up your (WordPress) site Ursus Minor

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).

Original article Published here >

How WebP images can speed up your (WordPress) site

* Optimise WP Website Images with ShortPixel – Super Fast Website, Optimised SEO, WordPress Plugin (Referral Ad)