A catalog page loads 40 product images totaling 8 MB. Google PageSpeed flags errors: "Serve images in next-gen formats" and "Properly size images." Bitrix stores originals in /upload/ and creates resized versions via CFile::ResizeImageGet() — but the format remains JPEG/PNG, without automatic WebP conversion. The result is slow loading and lost search rankings. Unoptimized images add 50–100 KB of traffic each. On a page with 40 products, that's 2–4 MB just for images. Search engines consider speed, especially on mobile: a slow site loses up to 20% of conversions. Comprehensive optimization — lossless compression, WebP, lazy loading — reduces page weight by 2–3 times and improves rankings.
We configure end-to-end multi-level optimization: resize, compression, WebP, lazy loading, and CDN delivery. With over 7 years of Bitrix development experience, we guarantee results. We've optimized images for 50+ projects, achieving PageSpeed improvements of 20+ points. Typical savings range from $500 to $2000 per month in bandwidth costs. Get your project evaluated — contact us for a free speed audit.
Impact of image optimization on Bitrix performance
Each unoptimized image adds 50–100 KB of traffic. On a catalog page with 40 items, that's 2–4 MB just for images. Search engines account for load speed, especially on mobile. A slow site loses up to 20% of conversions. Comprehensive optimization — lossless compression, WebP, lazy loading — reduces page weight by 2–3 times and lifts rankings. Compared to JPEG, WebP achieves 25–35% better compression, making it 1.3–1.5 times more efficient. Lazy loading reduces page load time by up to 40% compared to loading all images immediately.
Step-by-step plan for automatic optimization setup
- Audit current state: measure PageSpeed, analyze file structure in
/upload/, estimate volume and formats. -
Compression on upload: implement
OnAfterFileSavehandler withImageOptimizer::compress(). Limit side to 2000px, quality 85% JPEG / 9 PNG, strip EXIF. -
WebP conversion: set up
OnAfterGetResizeImagePathhandler to generate WebP copies. Configure Nginx to serve WebP based onAccept. -
Lazy loading and srcset: modify catalog component templates — add
loading="lazy",srcsetfor responsive resolutions. - Mass processing of existing files: run an agent that processes 100 files per step.
- Testing and monitoring: re-measure PageSpeed, verify WebP delivery, check cache compatibility.
Level 1: resize and compression on upload
The default CFile::ResizeImageGet() creates resized versions on first request and caches them in /upload/resize_cache/. The main problem is that originals are stored uncompressed, and managers upload 5–10 MB photos from their phones. We add an OnAfterFileSave event handler that compresses the file immediately after upload.
\Bitrix\Main\EventManager::getInstance()->addEventHandler( 'main', 'OnAfterFileSave', function (\Bitrix\Main\Event $event) { $file = $event->getParameter('FILE'); if (!in_array($file['CONTENT_TYPE'], ['image/jpeg', 'image/png', 'image/gif'])) { return; } $path = $_SERVER['DOCUMENT_ROOT'] . $file['SRC']; if (!file_exists($path)) { return; } \Local\Media\ImageOptimizer::compress($path, $file['CONTENT_TYPE']); } ); The ImageOptimizer class uses Imagick if available, otherwise GD. It strips EXIF, limits the maximum side to 2000px, and sets quality to 85% for JPEG or compression level 9 for PNG. After compression, the original takes about 30% of its original size on average. To process already uploaded files, we run a mass agent that iterates through 100 files per step.
How to set up WebP conversion in Bitrix?
WebP provides a 25–35% size reduction compared to JPEG at comparable quality. Browser support is 97%+ (all modern ones). Strategy: generate a WebP version alongside the original via the OnAfterGetResizeImagePath event, then let Nginx serve WebP to browsers that support the format.
\Bitrix\Main\EventManager::getInstance()->addEventHandler( 'main', 'OnAfterGetResizeImagePath', function (\Bitrix\Main\Event $event) { $result = $event->getParameter('RESULT'); $src = $result['src'] ?? ''; if (!$src || !preg_match('/\.(jpg|jpeg|png)$/i', $src)) { return; } $localPath = $_SERVER['DOCUMENT_ROOT'] . $src; $webpPath = preg_replace('/\.(jpg|jpeg|png)$/i', '.webp', $localPath); if (!file_exists($webpPath) && file_exists($localPath)) { \Local\Media\WebpConverter::convert($localPath, $webpPath); } } ); Example Nginx configuration
map $http_accept $webp_suffix { default ""; "~*webp" ".webp"; } server { location ~* ^(/upload/resize_cache/.+)\.(jpg|jpeg|png)$ { set $img_path $1.$2; set $webp_path $1.webp; if ($webp_suffix = ".webp") { add_header Vary Accept; try_files $webp_path $img_path =404; } try_files $img_path =404; expires 30d; add_header Cache-Control "public, immutable"; } } Why is lazy loading critical for SEO?
Lazy loading defers loading of off-screen images, reducing time to interactive. In the catalog component template, we add loading="lazy" and srcset for responsive resolutions.
<?php $img = \CFile::ResizeImageGet($element['PREVIEW_PICTURE'], ['width' => 300, 'height' => 300]); $img2 = \CFile::ResizeImageGet($element['PREVIEW_PICTURE'], ['width' => 600, 'height' => 600]); ?> <img src="<?= htmlspecialchars($img['src']) ?>" srcset="<?= htmlspecialchars($img['src']) ?> 300w, <?= htmlspecialchars($img2['src']) ?> 600w" sizes="(max-width: 768px) 300px, 600px" loading="lazy" width="300" height="300" alt="Automated image compression and WebP optimization for 1C-Bitrix" > Image format comparison
| Format | Compression | Quality | Support | File size |
|---|---|---|---|---|
| JPEG | Lossy | Good | 100% | 100% (baseline) |
| PNG | Lossless | Excellent | 100% | 200%+ (larger) |
| WebP | Lossy/lossless | Comparable to JPEG | 97% | 70-75% of JPEG |
| AVIF | Lossy/lossless | Better | 90%+ | 50-60% of JPEG |
Automatic conversion to WebP offers the best balance of compatibility and size savings. We use quality 82% (visually lossless). Proper image cache configuration ensures that optimized versions are served quickly. For mass upload optimization, our agent processes files in batches. Bitrix agent optimization reduces server load during bulk operations.
Common optimization issues
If WebP is not served, check the Accept header or Nginx location. EXIF data can be preserved if needed by disabling stripping in the optimizer. Lazy loading requires explicit width and height to prevent layout shifts.
What's included in media file optimization setup
- Compression on upload:
OnAfterFileSavehandler, EXIF removal, resize to 2000px, JPEG quality 85% / PNG compression level 9. - WebP conversion:
OnAfterGetResizeImagePathevent + Nginx configuration for WebP delivery. - Lazy loading and srcset: modification of catalog component templates.
- Mass optimization of existing files: agent with 100-file step.
- Testing: PageSpeed measurement, WebP delivery verification, cache compatibility check.
- Documentation: description of all changes, settings for support.
How long does the setup take?
- Basic package (compression + WebP + lazy loading) — 1–2 business days.
- Mass optimization of existing files — additional 4–8 hours.
- Integration with CDN or additional formats (AVIF) — discussed separately.
We guarantee completion within agreed timelines. Order the setup — we'll evaluate your project for free and propose the optimal solution. Contact us for a consultation and get up to 60% traffic savings.

