WebP image optimization in Magento 2: overview of solutions and automated approach

In a web environment where speed and user experience have become essential, image optimization plays a decisive role. Among modern formats, WebP has now established itself as a standard. Developed by Google, it combines low file size, excellent visual quality, and versatility, making it an ideal format for e-commerce sites that require performance and responsiveness.

Since Magento 2 does not natively offer full support for the WebP format, many third-party modules have emerged. Each one offers a different approach, with its own advantages and limitations. Here is an overview of the existing solutions before introducing a more effective method: automatic on-demand generation.

1. The solutions available on the market

1. Generation via CLI command

Some solutions work by running a command, for example bin/magento module:webp:generate.
This command scans all the images in the catalog and creates their corresponding WebP versions.

Advantages:

  • Enables complete and centralized conversion.
  • Useful during a migration or large-scale update.

Disadvantages:

  • Requires SSH access and technical skills.
  • Must be run again after every image modification or addition.
  • Can be very time-consuming and resource-intensive for large catalogs.
  • Therefore, this method is not suitable for daily use by merchants without technical expertise.

2. Generation via CRON job

Other modules automate the conversion through CRON jobs, scheduled to run at regular intervals.

Advantages:

  • Fully automated, requiring no human intervention.
  • Easier for the merchant.

Disadvantages:

  • Risk of server overload, especially with large catalogs.
  • Delay between image upload and its conversion, which can cause issues.

3. Hybrid approach: command + CRON

A combination of the two previous methods is sometimes offered: an initial command quickly generates the existing images, then a CRON job handles the conversion of new images.

Advantages:

  • Reduces the load on CRON jobs by starting with an already converted catalog.

Disadvantages:

  • Combines the drawbacks of the previous methods: technical complexity at the start, possible server load afterward.

2. Automatic generation: a more efficient alternative

A more effective approach consists of automatically generating WebP images on demand, without CRON jobs or commands.
You just need to select the image adapter in the admin interface:

Stores → Configuration → Advanced → Developer

Once the adapter is activated, the generation becomes completely transparent.

How it works

Magento 2 generates resized images in:
pub/media/catalog/product/cache/...

When an image is displayed for the first time, Magento:

  • retrieves the original image (e.g., media/catalog/product/my_image.jpg)
  • resizes it
  • stores it in the cache folder at the requested size

By default, Magento keeps the same format.
To have it generate a WebP image instead, you simply intercept this step.

Steps of the method

  1. Virtual renaming of the image in the DOM
    Even before the image exists, its path is modified.
    Example:
    my_image.jpg becomes my_image_jpg.webp
    The _jpg suffix makes it easy to locate the original image.
  2. Interception of generation by the image controller
    When Magento tries to serve my_image_jpg.webp, the controller:
    • identifies the original image (my_image.jpg)
    • resizes it as usual
    • converts it to WebP under the new name
    • saves it in the cache folder
  3. The WebP image is immediately available.
    Generation only occurs when necessary, never in bulk.

Advantages of this approach

  • No action required from the merchant, no CRON or CLI needed
  • Generation only on demand, avoiding unnecessary server load; only images actually viewed are converted
  • Completely transparent process
  • Optimized performance with no risk of overload on large catalogs

Conclusion

Traditional solutions based on CLI commands or CRON jobs remain functional but often come with constraints that can be difficult for merchants without technical expertise to manage. In contrast, automatic on-demand generation offers a more flexible, efficient, and above all, completely transparent approach. It integrates seamlessly with Magento 2’s native functionality and ensures continuous optimization without any additional effort.

For a modern Magento store, this method is undoubtedly the most suitable way to fully leverage the benefits of the WebP format.

meme webp mng