Why Image Compression Matters
Images typically account for 50-70% of a webpage's total size. Compressing images reduces page load time, improves Core Web Vitals (a Google ranking factor), saves bandwidth, and creates a better user experience — especially on mobile devices with slower connections.
Types of Image Compression
- Lossy compression: Permanently removes some image data to achieve smaller file sizes. JPEG uses lossy compression. At quality levels of 75-85%, the difference is virtually invisible to the human eye while achieving 60-80% size reduction.
- Lossless compression: Reduces file size without losing any data. PNG uses lossless compression. Smaller savings (10-30%) but the image is pixel-perfect identical to the original.
Image Formats Compared
- JPEG: Best for photographs and complex images with gradients. Lossy compression. Does not support transparency. Typical quality setting: 80-85%.
- PNG: Best for graphics, logos, and images with text or sharp edges. Lossless. Supports transparency (alpha channel). Larger file sizes than JPEG for photos.
- WebP: Modern format by Google. 25-35% smaller than JPEG at equivalent quality. Supports both lossy and lossless. Supports transparency. Supported by all modern browsers.
- AVIF: Even newer format. Up to 50% smaller than JPEG. Excellent quality. Browser support growing rapidly.
- SVG: Vector format — scales to any size without quality loss. Best for icons, logos, and illustrations. Not suitable for photographs.
Image Size Guidelines for Web
- Hero images: Under 200KB. Use JPEG at 80% quality or WebP.
- Thumbnails: Under 30KB. Resize to actual display dimensions.
- Blog post images: Under 100KB each.
- Total page weight: Keep all images under 1MB total for good Core Web Vitals.
Tips for Optimal Compression
- Resize images to their display dimensions before compressing — don't serve a 4000px image if it displays at 800px
- Use WebP format when possible (95%+ browser support)
- Implement lazy loading for images below the fold (
loading="lazy") - Use responsive images with
srcsetto serve different sizes for different screen widths - Enable browser caching for images with appropriate Cache-Control headers