โ† Back to Guides

How to Optimize Images for Web Performance

ยท Tags: image-optimization, web-performance, core-web-vitals, lcp, page-speed, seo

How to Optimize Images for Web Performance

Images represent 50 to 60 percent of a typical webpage's total downloaded bytes. Every unoptimized image adds seconds to your load time, increases your bounce rate, and damages your search engine ranking. Google's Core Web Vitals โ€” specifically Largest Contentful Paint (LCP) โ€” directly measure image loading performance, making image optimization one of the highest-impact changes you can make to your website.

This guide covers a complete image optimization strategy, from compression fundamentals to advanced delivery techniques.

1. Compress Every Image Before Publishing

Never upload a raw image directly from your camera, phone, or design tool. Compression should be the first step in your publishing workflow.

Key principles:

  • Photographs tolerate aggressive lossy compression. Start at quality 80 for JPEG and WebP, then adjust downward if file size targets demand it.
  • Screenshots, logos, and graphics benefit from lossless compression. PNG and lossless WebP preserve the sharp edges and text that lossy compression would blur.
  • AVIF offers the best compression ratios but requires more encoding time. Use it for images that are downloaded frequently and updated rarely.
  • Compress in the original format to avoid generation loss from unnecessary format conversions.

Expected savings:

A typical workflow that compresses images before upload reduces total image weight by 40 to 80 percent with minimal perceptible quality loss.

2. Serve the Right Dimensions

Serving a 4000-pixel-wide photo inside a 300-pixel-wide container is the most common performance mistake on the web. The browser downloads all 4000 pixels and then scales them down, wasting bandwidth and memory.

Create multiple size variants:

  • 320 to 480 pixels wide for mobile screens
  • 768 to 1024 pixels wide for tablets
  • 1200 to 1920 pixels wide for desktop displays
  • 2560 pixels wide for high-density retina displays (2x)

Match the largest variant to the maximum width the image will be displayed in your layout, multiplied by 2 for high-DPI screens.

3. Use Responsive Images with Srcset

The srcset and sizes attributes in HTML tell the browser which image size to download based on the user's viewport width and device pixel ratio.

<img
  src="photo-800.jpg"
  srcset="
    photo-400.jpg 400w,
    photo-800.jpg 800w,
    photo-1200.jpg 1200w,
    photo-1600.jpg 1600w
  "
  sizes="(max-width: 600px) 100vw, (max-width: 1200px) 50vw, 800px"
  alt="Descriptive text for accessibility and SEO"
/>

This single pattern can cut image bandwidth by 40 to 60 percent on mobile devices without any visible quality difference.

4. Optimize for Largest Contentful Paint (LCP)

LCP measures the time it takes for the largest visible element โ€” usually the hero image โ€” to render. Google considers an LCP of 2.5 seconds or less as good.

To optimize LCP for images:

  • Preload the hero image so the browser discovers it early. Add <link rel="preload" as="image" href="hero.webp"> to your document head.
  • Compress the hero image aggressively โ€” it is usually the first and largest asset the browser downloads.
  • Serve WebP or AVIF for the hero image with a JPEG fallback.
  • Size the hero image correctly. Do not serve a 4000-pixel image in a 1200-pixel hero slot.
  • Do not lazy load the hero image or any above-the-fold image. Lazy loading delays the download, which hurts LCP.

5. Enable Lazy Loading for Below-the-Fold Images

Images that are not visible on the initial screen do not need to load immediately. The loading="lazy" attribute tells the browser to defer image loading until the image is close to entering the viewport.

<img src="gallery-photo.jpg" loading="lazy" alt="Gallery image" />

Lazy loading reduces initial page weight by 30 to 50 percent on image-heavy pages. Combined with compression, the impact is transformative.

6. Remove Image Metadata

EXIF data โ€” camera settings, GPS coordinates, timestamps โ€” adds unnecessary bytes to every image. Stripping metadata typically saves 5 to 15 percent of file size with zero visual change. Make metadata removal a standard step in your compression workflow.

7. Use a Content Delivery Network (CDN)

A CDN distributes your images across servers worldwide, reducing the physical distance between the user and the image. This improves Time to First Byte for image requests.

Some CDNs also offer on-the-fly image transformation:

  • Automatic format negotiation (serve WebP or AVIF when supported)
  • Dynamic resizing based on device and viewport
  • Real-time compression adjustments

If a dedicated CDN is not an option, at minimum use HTTP/2 or HTTP/3 to allow multiple image downloads in a single connection.

8. Consider Image Decoding Performance

Large images not only take time to download but also take time to decode. The browser must decompress JPEG, PNG, WebP, or AVIF data before rendering it. JPEG and WebP decode quickly on most devices, while AVIF decoding is more computationally expensive โ€” a consideration for lower-end mobile devices.

Use the decoding="async" attribute on non-critical images to allow the browser to decode them without blocking other content:

<img src="photo.jpg" decoding="async" loading="lazy" alt="Description" />

Building Your Optimization Workflow

An end-to-end image optimization pipeline looks like this:

  1. Compress images in their original format using a quality-appropriate tool.
  2. Strip metadata during compression.
  3. Resize to the required display dimensions, creating multiple variants.
  4. Implement srcset and sizes in your HTML templates.
  5. Preload the hero image, lazy load everything below the fold.
  6. Serve from a CDN for global performance.
  7. Measure LCP and total image weight using Lighthouse or PageSpeed Insights.
  8. Iterate on quality settings until you meet your performance budget.

Start optimizing your images today with our free online image compressor. Upload images in PNG, JPEG, WebP, or AVIF format and download compressed versions that are ready for production โ€” no format conversion, no quality compromises.