Sail Knowledgebase

Image Optimization, Compression and WebP with Sail CLI

In this guide you will learn about image compression, optimization and conversion services provided by Sail Premium.

If you like Sail, don't forget to give us a star on GitHub!

Note: Image optimization is a paid feature available only for users with an active Sail Premium subscription.

Image optimization

After enabling Sail premium for your WordPress application, the image optimization service will be configured automatically. This will cause requests for images to be proxied to Sail's optimization service which will:

  • Resize/crop the image if resize parameters are provided
  • Convert JPG/PNG images to WebP if the Accept headers allow for image/webp
  • Compress/optimize the final image

Sail Premium will also enable a small plugin on your WordPress site which adds resize parameters to images. This enables users to change themes, update image sizes, etc., without having to regenerate thumbnails (and other image sizes).

It will also constrain content images to the content width defined by the theme. If you wish to disable this behavior, use a WordPress filter:

add_filter( 'sail_resize_images', '__return_false' );

Note that Sail does not replace your original images with compressed or optimized images, it is simply a proxy.

Caching

For existing sites with a lot of images you might notice some lag when displaying the optimized images for the first time after enabling premium. This lag is temporary due to the large queue of images that need processing coming from your site.

Resized and optimized images will be cached on your server indefinitely for performance reasons. If you wish to clear this cache, empty the /var/cache/nginx/premium directory on your server.

WebP

Converting to WebP will be done only for requests that explicitly state their support for the image/webp MIME type through the Accept header. This means that modern browsers will almost always receive a WebP image instead of JPG/PNG ones.

Supported types

The following image types are supported by Sail's image optimization proxy:

  • JPEG
  • PNG
  • WebP
  • AVIF
  • GIF
  • ICO
  • SVG
  • HEIC
  • BMP
  • TIFF

If you have any questions about image optimization with Sail, feel free to get in touch.