← Back to Blog

How to Optimize Images for Web: Complete Guide

Properly optimized images make websites fast without sacrificing visual quality. Here's your complete optimization workflow.

Step 1: Start with the Right Dimensions

Never upload images larger than needed:

  • Determine the maximum display size
  • Account for retina displays (2x pixel density)
  • Resize before compression

**Example:** An image displayed at 600px wide on a retina display needs to be 1200px wide maximum.

Step 2: Choose the Right Format

**Photographs:** WebP > JPEG **Graphics/logos:** SVG > PNG > WebP **Screenshots:** PNG or WebP (lossless) **Animations:** WebP > GIF

When in doubt, test both options and compare file sizes.

Step 3: Find Your Quality Sweet Spot

The goal is the smallest file that looks identical to the original:

1. Start at 80% quality 2. Compare to original at 100% zoom 3. If identical, try 70% 4. If degradation visible, go back up 5. Find the threshold for each image

Different images compress differently - photos with detail compress better than graphics.

Step 4: Remove Metadata

Images often contain hidden metadata: - EXIF data (camera settings, GPS) - Color profiles - Thumbnails

Stripping metadata can save 10-20KB per image without affecting quality.

Step 5: Consider Lazy Loading

Not all images need to load immediately:

  • Add loading="lazy" to images below the fold
  • Use intersection observer for more control
  • Prioritize above-the-fold images

Step 6: Implement Responsive Images

Serve different sizes based on viewport:

<img srcset="small.jpg 400w, medium.jpg 800w, large.jpg 1200w" sizes="(max-width: 600px) 400px, (max-width: 1000px) 800px, 1200px" src="medium.jpg" >

This serves appropriate sizes to different devices.

Step 7: Use a CDN

Content Delivery Networks improve image loading: - Serve from servers closer to users - Automatic format conversion - Caching and optimization - Reduced origin server load

Popular options: Cloudflare, CloudFront, Fastly, Cloudinary

Quick Optimization Checklist

  • [ ] Resized to correct dimensions
  • [ ] Chosen optimal format
  • [ ] Compressed to target quality
  • [ ] Metadata stripped
  • [ ] Lazy loading implemented
  • [ ] Responsive srcset added
  • [ ] CDN configured

Tools for Batch Optimization

For many images at once: - CompressSpark (online, bulk support with Pro) - ImageOptim (Mac) - FileOptimizer (Windows) - Sharp (Node.js library)

Measuring Results

After optimization, verify improvements: - Google PageSpeed Insights - WebPageTest - Lighthouse in Chrome DevTools

Target: All images should be appropriately sized and compressed per these tools.

Ready to compress your images?

Compress Images with CompressSpark