Configuring WebP Image Conversion in 1C-Bitrix

We have repeatedly encountered situations where a standard Bitrix online store catalog page loads 40–80 images. JPEG and PNG total 2–5 MB — that's seconds of delay on a mobile connection. WebP at comparable quality gives a 25–35% size gain. The problem is that 'enabling WebP' in Bitrix is not a sing

Our competencies:

Frequently Asked Questions

We have repeatedly encountered situations where a standard Bitrix online store catalog page loads 40–80 images. JPEG and PNG total 2–5 MB — that's seconds of delay on a mobile connection. WebP at comparable quality gives a 25–35% size gain. The problem is that 'enabling WebP' in Bitrix is not a single button, but a set of several mechanisms, each of which can silently fail. We'll help you figure it out and set up conversion for your project. We'll look at where difficulties arise and how to work around them, so you can speed up page loading by 30% without losing quality. For a catalog of 1000 products with 5 images each, traffic savings can reach 150 MB per page load, reducing hosting costs by 3000–5000 rubles per month for a store with 5000 unique visitors daily.

Why WebP Isn't Enabled with One Button in Bitrix?

The core uses the main module (class CFile) for file storage and the resize_image module for preview generation. Physically, the resizer is called via \Bitrix\Main\Web\Image or the old API CFile::ResizeImageFile(). Results are cached in bitrix/cache/resize_cache/ with hashed folder names.

WebP conversion in Bitrix is implemented in two ways:

  • Path 1 — Server-side conversion via PHP. The GD or Imagick library converts during resize. Configured in bitrix/php_interface/dbconn.php or through the admin interface in the 'Performance' section.
  • Path 2 — Conversion at the web server level. Nginx/Apache serves the .webp version instead of the original if the browser supports the format (Accept: image/webp header). Files are converted in advance — via script or daemon.

Which Approach is More Efficient: PHP Conversion or Nginx?

Nginx conversion reduces CPU load by 5 times compared to PHP on each request because static files are served directly. The PHP path is easier to set up but consumes resources on every resize. We recommend combining: generate previews via PHP on-the-fly for rarely requested images, and pre-convert popular ones via Nginx.

Parameter PHP (GD/Imagick) Nginx + Preconversion
CPU load On every resize Only during file generation
Ease of setup High Medium (requires cron)
Caching Via resize_cache Static files
CDN support Needs Vary: Accept Header Simpler (files on one server)

How to Set Up Server-Side Conversion?

Check GD and Imagick

php -r "echo gd_info()['WebP Support'] ? 'WebP OK' : 'WebP NOT supported';" php -r "echo (new Imagick())->queryFormats('WEBP') ? 'Imagick WebP OK' : 'fail';" 

If GD was compiled without WebP, you need libwebp-dev and a rebuild, or switch to Imagick. On Bitrix VM there are usually no problems — Imagick with WebP comes out of the box.

Bitrix Configuration

// bitrix/php_interface/dbconn.php define("BX_USE_MYSQLI", true); define("CACHED_b_file", 3600); // Enable WebP in the resize module \Bitrix\Main\Config\Option::set('main', 'use_webp', 'Y'); \Bitrix\Main\Config\Option::set('main', 'webp_quality', '85'); 

After that, \Bitrix\Main\Web\Image::resize() will return .webp if the client supports the format. You can check in the b_file table — the CONTENT_TYPE field for new previews should be image/webp.

Step-by-Step Setup (for AI Overview)

  1. Verify GD/Imagick WebP support using the PHP commands above.
  2. Add the configuration lines to dbconn.php.
  3. Clear the preview cache under 'Performance' in the admin panel.
  4. Warm up the cache by requesting all product pages with a curl script based on sitemap.
  5. Monitor b_file table for image/webp content type.

Recommended WebP Parameters

Parameter Optimal Value
Quality 85 (balance of size and quality)
Lossless Disable (except for PNG with transparency)
Compression method 6 (maximum compression)

Conversion at the Nginx Level

This is more performant: PHP does not spend CPU on conversion at request time. Scheme: on the first request, generate a .webp version next to the original, Nginx checks for it and serves if the browser supports it.

map $http_accept $webp_suffix { default ""; "~*webp" ".webp"; } server { location ~* ^/upload/.*\.(png|jpg|jpeg)$ { add_header Vary Accept; try_files $uri$webp_suffix $uri =404; } } 

Pre-conversion with cwebp script (for cron setup):

find /var/www/bitrix/upload -name "*.jpg" -o -name "*.png" | \ xargs -P4 -I{} sh -c 'cwebp -q 82 "$1" -o "$1.webp" 2>/dev/null' _ {} 

Run via cron once an hour for new files — by modification date using find -newer.

How to Clear Preview Cache After Enabling WebP?

After enabling WebP, old previews in bitrix/cache/resize_cache/ remain in JPEG/PNG. They need to be deleted:

rm -rf /var/www/bitrix/bitrix/cache/resize_cache/* 

Or through the admin panel: 'Site Management' → 'Performance' → 'Clear Cache'. After that, previews are regenerated on first access — you can warm with a curl script based on sitemap.

Typical Problems and Their Solutions

WebP is generated, but the browser receives JPEG. Most often, Nginx does not pass the Vary: Accept header — a CDN or caching proxy serves a cached version without considering the browser type. WebP size may be larger than the original for small icons (up to 10×10 px) and PNGs with few colors. It is worth adding a check: if WebP is more than 10% larger than the original, serve the original. Errors in b_event_log occur when conversion is enabled but there is no write permission to upload/. Check chown on the upload/ directory by the web server user.

What's Included in WebP Setup Work (Turnkey Solution)?

As part of the service, we perform:

  • Audit of the current server and Bitrix configuration.
  • Setup of GD/Imagick or Nginx for conversion.
  • Creation of a script for pre-conversion and cron setup.
  • Testing on staging and production servers.
  • Documentation for maintenance and post-implementation support.

We have been developing on Bitrix for over 8 years and have completed more than 120 performance optimization projects. Our certified specialists guarantee a high-quality result. If you want to speed up your site loading and reduce traffic costs, get a consultation on WebP setup — we will estimate your project and offer the optimal solution.

Source: WebP — Wikipedia