← CodeClarityLab Home
Browse by Category
+ added · updated 7d
← Back to glossary

Image Optimisation

performance Intermediate

Also Known As

image compression image performance AVIF WebP responsive images srcset sizes image loading next-gen image formats

TL;DR

Reducing image file size and delivery overhead through format choice (AVIF, WebP), compression, responsive sizing (srcset), lazy loading, and explicit dimensions — the single highest-impact performance lever for most websites.

Explanation

Images typically account for 50-75% of a page's total bytes. Optimisation has several dimensions: format (AVIF is 50% smaller than JPEG at equivalent quality; WebP is 30% smaller; use <picture> for progressive enhancement); compression (lossy vs lossless — most photography tolerates 75-85% quality without visible degradation); responsive sizing (srcset + sizes delivers the appropriately-sized image for each viewport — serving a 2000px image to a 400px mobile screen wastes 80% of the download); lazy loading (defer off-screen images with loading='lazy'); dimensions (explicit width and height prevent layout shift as images load); priority (the LCP image needs fetchpriority='high' and should never be lazy-loaded). CDN image transformation (Cloudflare Images, Imgix, Cloudinary) handles format conversion, resizing, and compression automatically at edge — eliminating most manual optimisation work.

Common Misconception

All images should be lazy-loaded for maximum performance — lazy-loading the LCP image (the largest above-fold image) is one of the most common causes of LCP regression; the hero image must load immediately with fetchpriority='high'.

Why It Matters

A product listing page with 30 unoptimised JPEG images at 500KB each adds 15MB to the initial page load — converting to WebP/AVIF, using srcset, and lazy loading reduces this to under 1MB, transforming LCP from 8 seconds to under 2 seconds on mobile.

Common Mistakes

  • Loading the same large image at all viewport sizes — serve appropriately-sized images with srcset/sizes; a mobile user shouldn't download a 2000px image.
  • Lazy-loading the LCP (hero) image — delays the most important content and directly harms LCP score.
  • No explicit width and height attributes — browser can't reserve space, images shift content as they load (CLS).
  • Serving JPEG/PNG when AVIF/WebP is available — modern formats offer 30-50% size reduction at equivalent quality.
  • Not setting decoding='async' on large non-LCP images — synchronous decode blocks the main thread.

Avoid When

  • Do not lazy-load the LCP (hero) image — it must load as fast as possible.
  • Do not apply heavy lossy compression to images where quality is critical (medical imaging, product photography with fine detail).

When To Use

  • Apply image optimisation to every image-heavy page — typically the highest ROI performance improvement available.
  • Use CDN image transformation (Cloudflare Images, Imgix) to automate format conversion and responsive resizing.
  • Use <picture> with AVIF and WebP sources with JPEG/PNG fallback for progressive enhancement across browsers.

Code Examples

✗ Vulnerable
<!-- Same large image served to all devices -->
<img src="product-2000px.jpg" alt="Product">

<!-- LCP image lazy-loaded -->
<img src="hero.jpg" alt="Hero" loading="lazy">

<!-- No dimensions — causes CLS -->
<img src="card.jpg" alt="Card">
✓ Fixed
<!-- LCP hero: eager, high priority, explicit dimensions -->
<img src="hero.jpg" alt="Hero" fetchpriority="high"
     width="1200" height="600">

<!-- Responsive image with next-gen format fallback -->
<picture>
  <source srcset="product.avif" type="image/avif">
  <source srcset="product.webp" type="image/webp">
  <img src="product.jpg" alt="Blue ceramic mug"
       srcset="product-400.jpg 400w, product-800.jpg 800w"
       sizes="(max-width: 600px) 400px, 800px"
       loading="lazy" decoding="async"
       width="800" height="800">
</picture>

Added 6 Apr 2026
Views 10
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
1 ping W 0 pings T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 1 ping S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 1 ping T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T
No pings yet today
No pings yesterday
Google 2 ChatGPT 1 Ahrefs 1
crawler 3 crawler_json 1
DEV INTEL Tools & Severity
🟠 High ⚙ Fix effort: Medium
⚡ Quick Fix
Add width and height to every img; use loading='lazy' on below-fold images; add fetchpriority='high' to hero/LCP image; convert to WebP or AVIF; use srcset for responsive sizing
📦 Applies To
html web
🔍 Detection Hints
img without width/height; img without loading=lazy below fold; img without srcset on variable-width layouts
Auto-detectable: ✓ Yes lighthouse pagespeed-insights squoosh imageoptim cloudinary
⚠ Related Problems
🤖 AI Agent
Confidence: Medium False Positives: Low ✗ Manual fix Fix: Medium Context: Line

✓ schema.org compliant