Images account for roughly 50% of the average web page's total weight. For developers, optimizing images is one of the highest-use performance improvements available — it directly impacts Core Web Vitals, page load time, and user experience.
This guide covers the complete image optimization pipeline for web developers, from format selection and compression to responsive images and delivery strategies.
The Image Optimization Pipeline
A proper image optimization workflow has four stages:
- Format selection — Choose the right format for the content
- Resizing — Scale to the actual display dimensions
- Compression — Reduce file size at acceptable quality
- Delivery — Serve efficiently with responsive images, lazy loading, and CDN
Each stage compounds the savings. Skipping any one of them leaves performance on the table.
Format Selection: WebP vs JPG vs AVIF vs PNG
Choosing the right format is the single most impactful decision.
| Format | Best For | Typical Size (vs uncompressed) | Transparency | Browser Support |
|---|---|---|---|---|
| WebP | Photos + graphics | 25-35% smaller than JPG | Yes | 97%+ |
| AVIF | Photos | 30-50% smaller than JPG | Yes | 92%+ |
| JPG | Photos (fallback) | Baseline | No | 100% |
| PNG | Graphics, text, transparency | 2-5x larger than JPG for photos | Yes | 100% |
| SVG | Icons, logos, simple graphics | Tiny (vector) | Yes | 100% |
Decision Tree
- Photo without transparency? Use WebP, fallback to JPG.
- Photo with transparency? Use WebP with alpha, fallback to PNG.
- Screenshot or text-heavy image? PNG or WebP lossless.
- Icon or logo? SVG if possible, otherwise 8-bit PNG.
- Complex illustration? WebP or PNG depending on color count.
BestPNG's format converter can convert between these formats directly in the browser.
Resizing: The Biggest Win Most Developers Miss
The most common image optimization mistake is compressing a 4000x3000 photo and serving it in a 400px-wide container. Even at JPG quality 50%, a 12-megapixel image is far larger than necessary.
Rule of thumb: The image file should be no wider than 2x the CSS display width (for retina screens).
| CSS Display Width | Maximum Image Width | Why |
|---|---|---|
| 400px | 800px | 2x for retina |
| 800px | 1600px | 2x for retina |
| 1200px | 2400px | 2x for retina |
| Full viewport (1920px) | 2560px | Reasonable upper bound |
Use BestPNG's resize tool to scale images to target dimensions before compressing.
Compression Settings for Web
After selecting the right format and resizing, apply compression:
JPG/WebP Compression
- Hero images: Quality 82-88%, target under 200 KB
- Content images: Quality 80-85%, target under 100 KB
- Thumbnails: Quality 75-80%, target under 30 KB
PNG Compression
- 8-bit (256 colors): For icons, logos, simple graphics
- Strip metadata: Always remove non-essential chunks
- Consider WebP instead: For anything over 100 KB
BestPNG's compress tool handles all of these with adjustable quality controls.
Responsive Images with srcset
Serving a single image to all devices wastes bandwidth on mobile. Use the srcset attribute to serve different sizes:
<img
src="image-800.webp"
srcset="
image-400.webp 400w,
image-800.webp 800w,
image-1200.webp 1200w,
image-1600.webp 1600w
"
sizes="(max-width: 600px) 100vw, 800px"
alt="Description"
width="800"
height="600"
loading="lazy"
/>
This tells the browser to pick the smallest image that fits the current viewport and screen density. The savings on mobile can be 50-80%.
Generating Multiple Sizes
For each content image, generate 3-4 sizes (e.g., 400, 800, 1200, 1600px wide). BestPNG's resize tool can help create these variants.
Lazy Loading
Images below the fold should not block initial page load. The loading="lazy" attribute defers loading until the image is near the viewport.
<img src="photo.webp" loading="lazy" alt="Description" width="800" height="600" />
Important: Do not lazy-load above-the-fold images (hero images, LCP elements). These should load immediately with loading="eager" or fetchpriority="high".
CDN and Caching
Serve images from a CDN with proper cache headers:
- Cache-Control:
public, max-age=31536000, immutablefor content-hashed filenames - CDN: Use Cloudflare, AWS CloudFront, or similar to serve images from edge locations globally
- Cloudflare R2: Zero egress fees make it well-suited for image storage and delivery
Image CDN Services
For dynamic resizing and format conversion at the edge, consider image CDN services like Cloudflare Images, Imgix, or Cloudinary. These can resize, compress, and convert formats on-the-fly based on request parameters.
Build Pipeline Integration
Automate image optimization in your build process:
Next.js
Next.js provides a built-in <Image> component that handles resizing, format conversion (WebP/AVIF), and lazy loading automatically:
import Image from 'next/image';
<Image
src="/photos/product.jpg"
width={800}
height={600}
alt="Product photo"
/>
Static Site Generators
For static sites, optimize images at build time using sharp, imagemin, or similar tools in your build script.
Pre-upload Optimization
For user-uploaded images or CMS content, optimize before upload using BestPNG's tools. This keeps consistent quality regardless of what the uploader provides.
Measuring Results
Track your image optimization progress with these tools:
- Google PageSpeed Insights — Identifies unoptimized images and provides LCP timing
- WebPageTest — Detailed waterfall showing image load times
- Chrome DevTools Network tab — Filter by "Img" to see individual image sizes and load times
- Lighthouse — "Properly size images" and "Serve images in next-gen formats" audits
Target Metrics
| Metric | Good | Needs Work | Poor |
|---|---|---|---|
| LCP | Under 2.5s | 2.5-4.0s | Over 4.0s |
| Total image weight | Under 500 KB | 500 KB - 1.5 MB | Over 1.5 MB |
| Largest single image | Under 200 KB | 200-500 KB | Over 500 KB |
Frequently Asked Questions
Should I use WebP or AVIF?
WebP has broader browser support (97%+) and is safer as a default. AVIF produces smaller files but encoding is slower and support is at 92%. Use both with the <picture> element for maximum savings, with JPG as the final fallback.
Is client-side compression good enough? For user-uploaded content, client-side compression (like BestPNG) is excellent — it reduces upload time and server storage. For your own site assets, optimize during the build process for maximum control.
How do I handle retina displays?
Serve images at 2x the CSS display size. A 400px-wide container needs an 800px-wide image for retina. Use srcset with width descriptors so the browser picks the right size automatically.
What about SVG for icons? SVG is well-suited for icons and logos — it scales to any size without quality loss and is typically smaller than equivalent PNGs. Use SVG wherever the graphic is simple enough to represent as vector paths.
Does image format affect SEO? Indirectly, yes. Faster page load (from optimized images) improves Core Web Vitals, which is a ranking signal. Google also recommends "next-gen formats" (WebP, AVIF) in PageSpeed Insights.
Conclusion
Image optimization is a systematic process: choose the right format, resize to target dimensions, compress at the right quality, and deliver efficiently. Each step compounds the savings.
For the compression and resizing steps, BestPNG's compress and resize tools handle the job directly in the browser — free, private, and with no file limits.