Meilleures pratiques pour l'optimisation d'images web en 2025

Images account for about 50% of the average web page's weight, making them the biggest opportunity for performance optimization. In 2025, with Core Web Vitals being a ranking factor and user expectations higher than ever, proper image optimization is non-negotiable.

This guide covers the complete picture of modern web image optimization, from file formats to delivery strategies.

1. Responsive Images: Serve the Right Size

Never make users download images larger than their device can display. Use responsive images to serve appropriately sized images for different screen sizes.

Using srcset and sizes

<img
  src="image-800.jpg"
  srcset="
    image-400.jpg 400w,
    image-800.jpg 800w,
    image-1200.jpg 1200w,
    image-1600.jpg 1600w"
  sizes="(max-width: 400px) 100vw,
         (max-width: 800px) 50vw,
         800px"
  alt="Description">

The browser will:

  • Check the device screen size
  • Calculate which image is optimal
  • Download only that image
  • Use higher resolution on Retina displays

Art Direction with <picture>

Use the picture element when you want different crops for different screen sizes:

<picture>
  <source media="(max-width: 600px)" srcset="portrait.jpg">
  <source media="(max-width: 1200px)" srcset="landscape.jpg">
  <img src="wide.jpg" alt="Description">
</picture>

2. Modern Image Formats

2025 is the year to fully embrace modern formats with proper fallbacks.

AVIF: The New Champion

AVIF offers the best compression available, typically 20-30% smaller than WebP:

  • Supported in Chrome, Firefox, Opera, and Safari 16+
  • Best for photos and complex images
  • Supports HDR and wide color gamut
  • Slower to encode but worth it for high-traffic images

WebP: The Reliable Workhorse

WebP is now supported in 95%+ of browsers:

  • 25-35% smaller than JPG
  • Faster to encode than AVIF
  • Good for both photos and graphics
  • Should be your primary format with JPG fallback

The Modern Format Strategy

<picture>
  <!-- Newest format for maximum savings -->
  <source srcset="image.avif" type="image/avif">

  <!-- Modern format with great support -->
  <source srcset="image.webp" type="image/webp">

  <!-- Universal fallback -->
  <img src="image.jpg" alt="Description">
</picture>

3. Lazy Loading

Don't load images until they're needed. Native lazy loading is now supported in all modern browsers:

<img src="image.jpg" alt="Description" loading="lazy">

When to Use Lazy Loading

  • Use it: Images below the fold, galleries, long articles
  • Don't use it: Above-the-fold hero images, critical content
  • Consider eagerly loading: The first 2-3 images on the page

Advanced: Intersection Observer

For more control, use the Intersection Observer API with a loading placeholder:

const imageObserver = new IntersectionObserver((entries) => {
  entries.forEach(entry => {
    if (entry.isIntersecting) {
      const img = entry.target;
      img.src = img.dataset.src;
      imageObserver.unobserve(img);
    }
  });
});

document.querySelectorAll('img[data-src]').forEach(img => {
  imageObserver.observe(img);
});

4. Image Dimensions and CLS

Always specify width and height to prevent Cumulative Layout Shift (CLS):

<!-- Bad: No dimensions -->
<img src="image.jpg" alt="Description">

<!-- Good: Dimensions specified -->
<img src="image.jpg" alt="Description" width="800" height="600">

<!-- Better: With CSS aspect ratio -->
<img src="image.jpg" alt="Description" width="800" height="600">

Modern browsers use the width/height attributes to calculate aspect ratio, even if you style the image with CSS.

5. Preloading Critical Images

Preload your LCP (Largest Contentful Paint) image to improve loading times:

<head>
  <link rel="preload" as="image" href="hero.jpg">
  <!-- For modern formats with fallback -->
  <link rel="preload" as="image" href="hero.avif" type="image/avif">
  <link rel="preload" as="image" href="hero.webp" type="image/webp">
</head>

Warning: Only preload the LCP image. Preloading too many resources defeats the purpose.

6. Content Delivery Network (CDN)

A CDN can dramatically improve image delivery:

Image CDN Benefits

  • Automatic optimization: Format conversion, quality adjustment, resizing on-the-fly
  • Global distribution: Images served from servers closest to your users
  • Bandwidth savings: Only generate sizes that are actually requested
  • Cache efficiency: Popular images stay cached at edge locations

Popular Image CDN Services

  • Cloudflare Images: Simple pricing, automatic optimization
  • Cloudinary: Powerful transformations, generous free tier
  • imgix: Advanced features, great DX
  • ImageKit: Real-time optimization, good pricing

URL-based Transformations

Most image CDNs let you transform images via URL parameters:

https://cdn.example.com/image.jpg?w=800&q=85&f=webp

This eliminates the need to pre-generate multiple sizes.

7. Performance Budgets

Set and enforce performance budgets for images:

  • Total page weight: Keep images under 1.5MB total
  • LCP image: Under 200KB (compressed)
  • Individual images: Rarely exceed 150KB
  • Icons/logos: Keep under 20KB

8. Monitoring and Testing

Continuously monitor your image performance:

Tools for Testing

  • Google PageSpeed Insights: Identifies image optimization opportunities
  • WebPageTest: Detailed waterfall charts showing image load times
  • Chrome DevTools: Network tab shows actual sizes transferred
  • Lighthouse: Automated audits for image best practices

Key Metrics to Watch

  • LCP: Should be under 2.5s (image loading is often the bottleneck)
  • CLS: Should be under 0.1 (missing dimensions cause this)
  • Total page weight: Images should be <50% of total
  • Number of requests: Consider spriting or bundling small images

9. Image Optimization Checklist

Use this checklist for every image you add to your site:

  • □ Choose appropriate format (WebP for most, PNG only when needed)
  • □ Resize to maximum display size (remember 2x for Retina)
  • □ Compress appropriately (75-85% quality for photos)
  • □ Remove unnecessary metadata
  • □ Specify width and height attributes
  • □ Add descriptive alt text
  • □ Use loading="lazy" for below-the-fold images
  • □ Implement responsive images with srcset/sizes
  • □ Provide modern format with fallback
  • □ Test on actual devices and slow connections

10. Advanced Techniques

Low Quality Image Placeholders (LQIP)

Show a blurred placeholder while the full image loads:

<div class="image-container">
  <img src="tiny-blurred.jpg" class="lqip">
  <img src="full-image.jpg" class="full-image" loading="lazy">
</div>

CSS Sprites for Icons

Combine multiple small images into a single sprite sheet to reduce HTTP requests:

.icon {
  background-image: url('sprite.png');
  width: 32px;
  height: 32px;
}
.icon-home { background-position: 0 0; }
.icon-user { background-position: -32px 0; }

SVG for Logos and Icons

Use SVG for logos and simple graphics:

  • Infinitely scalable
  • Tiny file sizes (often 1-5KB)
  • Can be styled with CSS
  • No raster artifacts at any size

Framework-Specific Solutions

Next.js Image Component

import Image from 'next/image'

<Image
  src="/image.jpg"
  alt="Description"
  width={800}
  height={600}
  placeholder="blur"
/>

WordPress

WordPress automatically generates multiple sizes. Use themes that implement srcset properly, and consider plugins like:

  • ShortPixel or Imagify for automatic compression
  • WP Rocket for lazy loading and WebP conversion

Common Mistakes to Avoid

  • Serving uncompressed images: The #1 performance killer
  • Missing width/height: Causes layout shift
  • Lazy loading LCP image: Delays the most important metric
  • Not using CDN: Leaving performance on the table
  • Ignoring mobile: Mobile users suffer most from poor image optimization
  • Over-optimizing: Visible artifacts harm user experience

Conclusion

Modern web image optimization is a multi-faceted discipline combining the right formats, responsive delivery, lazy loading, CDNs, and performance monitoring. By following these best practices, you can dramatically improve your site's loading times, Core Web Vitals scores, and user experience.

Start with the basics (compression and resizing), then progressively enhance with modern formats, responsive images, and advanced techniques. Measure the impact using real-user data, and iterate. Your users - and your search rankings - will thank you.

Questions fréquemment posées

Retour au Blog