Skip to main content

Overview

We built a smart compression system using that automatically selects the optimal output format based on multiple factors, ensuring the best possible compression while maintaining quality. This intelligent approach delivers smaller files without requiring manual format selection.

Optimization Process

1

Browser capability detection

Analyzes Accept header and User-Agent to determine supported formats.
Modern browsers receive AVIF or WebP for optimal performance.
2

Content type analysis

Evaluates whether the content is a photo, graphic, or contains text to choose the best compression algorithm.
3

File size optimization

Compares output sizes and selects the format with the best compression ratio while maintaining quality.Format priority: AVIF → WebP → JPEG → PNG

Format Selection Logic

The system follows this decision tree when no explicit format is specified:
  • Modern Browsers
  • WebP Fallback
  • Legacy Support
Browser supports AVIF:
Content Analysis → AVIF encoding → Size comparison → Deliver AVIF
AVIF provides up to 50% better compression than JPEG with equivalent visual quality.

Manual Override

While automatic selection is recommended, you can force a specific format when needed:
  • Force AVIF
  • Force WebP
  • Force JPEG
GET /t/format:avif/quality:80/image.jpg
Explicitly request AVIF output regardless of browser support.
Manual format selection bypasses intelligent optimization. Only use this when you have specific requirements that override automatic selection.

Compression Statistics

Typical compression improvements by format:
PNG to AVIF (50-70%)
60%
JPEG to AVIF (40-50%)
45%
PNG to WebP (25-40%)
32.5%
JPEG to WebP (25-35%)
30%
Actual savings vary based on image content, quality settings, and original compression level. Reducing image size can reduce file size even more.