Skip to content

Image Optimization for Web Performance Fix

DodaTech Updated 2026-06-24 3 min read

In this tutorial, you'll learn about Image Optimization for Web Performance Fix. We cover key concepts, practical examples, and best practices.

Your website loads slowly and Lighthouse reports "Properly size images" and "Serve images in next-gen formats" β€” large PNG/JPEG images are served at resolutions much higher than the display size, or old formats are used instead of WebP/AVIF.

Step-by-Step Fix

1. Find oversized images

Use Chrome DevTools:

  • Open DevTools > Network > Img filter
  • Sort by Size
  • Click an image to see the natural dimensions vs display dimensions

2. Use responsive images with srcset

<!-- Wrong β€” one image for all screen sizes -->
<img src="hero-1920.jpg" alt="Hero image">

<!-- Right β€” serve different sizes for different screens -->
<img src="hero-480.jpg"
     srcset="hero-480.jpg 480w,
             hero-768.jpg 768w,
             hero-1024.jpg 1024w,
             hero-1920.jpg 1920w"
     sizes="(max-width: 480px) 480px,
            (max-width: 768px) 768px,
            (max-width: 1024px) 1024px,
            1920px"
     alt="Hero image">

3. Convert to WebP format

# Convert JPEG to WebP
cwebp -q 80 input.jpg -o output.webp

# Convert PNG to WebP
cwebp -q 90 input.png -o output.webp

# Expected output
# Saved file output.webp (originally 500KB -> now 120KB, 76% smaller)
<!-- Wrong β€” only using JPEG -->
<img src="photo.jpg" alt="Photo">

<!-- Right β€” use <picture> with WebP fallback -->
<picture>
  <source srcset="photo.webp" type="image/webp">
  <source srcset="photo.jpg" type="image/jpeg">
  <img src="photo.jpg" alt="Photo">
</picture>

4. Compress with lossy optimization

# JPEG optimization (lossy)
jpegoptim --max=85 --strip-all input.jpg

# PNG optimization (lossless)
optipng -o7 input.png

Common Mistakes

Mistake Fix
Using 4000px wide images when display is 800px Use responsive srcset with appropriate sizes
Serving PNG for photographs Use JPEG or WebP for photos, PNG only for transparency
No lazy loading below the fold Add loading="lazy" to all images not in the initial viewport
No compression on uploaded images Compress server-side during upload
Ignoring WebP browser support Use <picture> with JPEG/PNG fallbacks

Prevention

  • Set maximum image dimensions in the CMS or upload pipeline.
  • Automatically convert all uploaded images to WebP.
  • Use an image CDN (Cloudinary, imgix) for automatic optimization.
  • Set up a build step that compresses and converts all static images.
  • Use Lighthouse CI to enforce image budget in CI/CD.

DodaTech Tools

Doda Browser automatically optimizes images for bandwidth-constrained connections using WebP conversion. DodaZIP compresses image archives with metadata stripping for privacy. Durga Antivirus Pro includes image scanning capabilities that process compressed formats efficiently.

Common Mistakes with optimization

  1. Using head and tail instead of pattern matching, causing runtime errors on empty lists
  2. Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks
  3. Using return to exit a function early instead of wrapping a pure value in the monad

These mistakes appear frequently in real-world IMAGE code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

How much can image optimization improve performance?

Image optimization typically reduces page weight by 50-80%. For image-heavy sites, this can cut total page size from 5MB to under 1MB and improve load time by 2-5 seconds. ||| What is the best image format for the web? WebP is currently the best widely-supported format (supported in all modern browsers). AVIF offers better compression but has limited support. Always provide JPEG/PNG fallbacks. ||| Do I need to optimize images if I use a CDN? Yes. CDNs cache whatever you send them. If you send 5MB uncompressed images, the CDN caches and serves 5MB images. Optimize before uploading to the CDN.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro