Performance

Optimising images for the web

A practical checklist for faster pages

A step-by-step approach to image performance: get the dimensions right first, then the format, then compression, then loading priority and caching, with the Core Web Vitals each step affects and a checklist you can run through before every release.

On this page

Images are the heaviest thing on most web pages and the easiest to fix. Unlike JavaScript bundles or third-party scripts, they rarely need an architectural decision: a handful of habits, applied in the right order, removes most of the weight without anyone noticing a difference in quality. This guide sets out that order and ends with a checklist to run through before a release.

Why images dominate page weight

The HTTP Archive's Web Almanac has reported year after year that images account for the largest share of bytes transferred by the median web page, ahead of scripts, fonts and markup. The reasons are mundane. Images are exported once and forgotten; a hero photograph uploaded at camera resolution stays there; editors paste screenshots at whatever size their display produced; a format chosen in 2012 is still the one the template expects. All of it compounds, because a single oversized image can outweigh every other asset on the page combined.

The good news is that image bytes are mostly waste: pixels nobody will see, formats two generations old and metadata the browser ignores can all be removed with no visible change.

The order of operations

The steps below are listed in the order that gives the largest savings first, which is also the order they depend on one another. Compressing before resizing wastes effort; choosing a format before deciding dimensions means choosing twice.

Step What you decide Why it comes here
1. Dimensions How many pixels the image actually needs Removing pixels saves more than any other step and makes every later step cheaper
2. Format Lossy or lossless; modern format with fallback Depends on content and on size, which you have just fixed
3. Compression Quality setting, palette reduction, metadata Only meaningful once pixels and format are final
4. Loading Which images load first, which wait Decides whether the bytes you kept arrive when needed
5. Delivery Caching, CDN, content negotiation Makes the second visit nearly free and the first faster
1. Dimensions, then 2. Format, then 3. Compression, then 4. Loading priority, then 5. Delivery and caching1Dimensions2Format3Compression4Loading priority5Delivery andcaching
Work through the steps in this order: each one depends on the decisions made before it, and the earlier steps save the most bytes.

Step 1: the right dimensions

An image should be exported at the largest size it will be displayed, multiplied by the highest device pixel ratio you intend to serve well, and no larger. A 4000-pixel photograph in a 700-pixel column sends several times as many pixels as even a 2× screen can show. Work out the display width at each breakpoint, export the candidates you need and describe them with srcset and sizes, so a phone fetches the small file and a large monitor the large one. The guide to image sizes walks through the arithmetic and the markup; the dimensions checker quickly shows which files are far larger than their slots, and Lighthouse's “Properly size images” audit flags the same thing from the browser's point of view.

Resizing is also the step most worth doing in bulk: the batch resizer applies one maximum width to a set of files and leaves images that are already small enough alone.

Step 2: the right format, with fallbacks

Photographs belong in a lossy format, graphics in a lossless one, and anything vector in SVG; the format guide has the full decision table. For the web the modern formats earn their place: Google's figures put lossy WebP at 25–34 % smaller than JPEG at equivalent quality and lossless WebP about 26 % smaller than PNG, and AVIF generally does better still for photographs. WebP is supported in every current browser; AVIF is supported in current versions of the major browsers but not older installations, so serve it with a fallback.

There are two ways to deliver fallbacks. The <picture> element lists sources in order of preference and the browser picks the first type it supports:

<picture>
  <source type="image/avif" srcset="photo.avif" />
  <source type="image/webp" srcset="photo.webp" />
  <img src="photo.jpg" width="1200" height="800" alt="Workshop bench with tools" loading="lazy" decoding="async" />
</picture>

The alternative is content negotiation: the server or CDN inspects the request's Accept header and returns AVIF, WebP or JPEG from the same URL, adding Vary: Accept so caches keep the variants apart. Negotiation keeps the markup simple; <picture> keeps the infrastructure simple. Either way, convert from the best original you have – the JPG to WebP and PNG to WebP converters re-encode whatever you give them, so start from the highest-quality source rather than an already compressed export.

Two special cases: animated GIFs are nearly always better served as a muted, looping, autoplaying video at a fraction of the size, and small decorative shapes are often better drawn with CSS or inline SVG than shipped as bitmaps.

Step 3: compression

With dimensions and format settled, compression is a question of picking a quality value you can live with and removing what the browser does not need. For lossy formats, start around quality 75–85, compare against the source at display size, and lower the value until artefacts appear, then step back. For PNG, palette reduction gives far larger savings than any lossless optimiser, at the cost of colour fidelity in gradients and photographs. The compression guide explains both and why the same setting gives such different savings on different images.

Strip metadata by default. Camera EXIF blocks, embedded thumbnails and XMP packets can add tens of kilobytes and may include GPS coordinates you did not intend to publish. Two items need care: apply the EXIF orientation to the pixels before dropping the tag, or phone photos appear sideways, and keep the ICC colour profile or convert to sRGB before removing it, or wide-gamut photos from recent phones look slightly flat. The image compressor and the batch compressor rotate the pixels to match the orientation tag before stripping metadata, and report the real size change for each file, including when an already compressed file would get larger. The format inspector shows which metadata a file still carries.

Step 4: loading priority

Bytes that arrive at the right moment feel faster than fewer bytes arriving late. Three attributes control this.

loading="lazy" tells the browser not to fetch an image until it is near the viewport. It is supported natively in all current browsers and is right for everything below the fold: article images, galleries, footers. It is wrong for anything visible at load, and especially for the largest image in the first screen, because delaying that image delays the page's Largest Contentful Paint; Lighthouse reports this mistake explicitly.

fetchpriority="high" does the opposite: it asks the browser to fetch the image ahead of other resources. Use it on one image per page – the hero or product shot that forms the LCP element. Browsers that do not recognise the attribute ignore it harmlessly.

decoding="async" lets the browser decode an image off the critical path so a large decode does not hold up the rest of the page. It is a sensible default for anything that is not the LCP image.

If the LCP image is a CSS background, the browser discovers it late, after the stylesheet is parsed. Prefer an <img> with object-fit: cover, or preload the background with <link rel="preload" as="image" href="hero.jpg" fetchpriority="high">, adding imagesrcset and imagesizes if the image is responsive.

Step 5: delivery and caching

Image files that never change should be cached for as long as possible. The standard pattern is a fingerprint in the file name – hero.3f9a2c.webp – served with Cache-Control: public, max-age=31536000, immutable, so a returning visitor's browser never asks for it again and a changed image gets a new name rather than an invalidation. Files whose names cannot change, such as user uploads at stable URLs, need a shorter lifetime and an ETag for cheap revalidation.

A content delivery network places those files close to the visitor and takes load off your origin; many CDNs also resize, convert and negotiate formats on the fly, replacing the build-time steps above with URL parameters. Whichever you use, check the response headers once in the browser's network panel; images served with no caching at all are common.

Core Web Vitals: what images affect

Google's Core Web Vitals thresholds for a “good” experience, measured at the 75th percentile of page loads, are a Largest Contentful Paint of 2.5 seconds or less, a Cumulative Layout Shift of 0.1 or less and an Interaction to Next Paint of 200 milliseconds or less. Images bear directly on the first two.

LCP is very often an image, and everything in steps 1 to 5 shortens it: fewer bytes, a modern format, high fetch priority, no lazy loading on that element and a warm cache.

CLS is caused by images when the browser does not know their size in advance and the layout jumps once they arrive. Give every <img> its intrinsic width and height attributes, or a CSS aspect-ratio, so space is reserved before the first byte downloads; Lighthouse checks this under “Image elements have explicit width and height”.

INP is mostly about script, not images, though decoding a very large image on the main thread can delay a response; decoding="async" and sensible dimensions prevent that.

Batch workflows

Applying all of this to one hero image is easy; applying it to a library of two thousand images needs a repeatable process. Three patterns are common:

  • Build-time processing, where a static site generator or framework image component produces the resized, converted and compressed variants at build time. Deterministic and cache-friendly, but slow on large libraries.
  • On-demand processing through an image CDN that transforms the original on first request and caches the result. Flexible, with running costs.
  • Pre-processing before upload, where images are resized, converted and compressed on the author's machine and the CMS stores only finished files. Simple, with no infrastructure.

The batch tools on this site support the third pattern: they process dozens of files at once entirely in the browser, so nothing is uploaded anywhere, and produce a ZIP ready for the CMS. Whichever pattern you adopt, keep the originals somewhere safe; every step here is one-way.

The checklist

Check Pass condition
Dimensions No image is more than about 2× its largest displayed CSS width
Responsive markup Content images use srcset and an honest sizes; fixed-size images use 1x/2x descriptors
Format Photos are WebP or AVIF with a JPEG fallback; graphics are palette PNG, lossless WebP or SVG; no long animated GIFs
Compression Quality chosen by inspection at display size; nothing re-encoded larger
Metadata EXIF, thumbnails and XMP stripped; orientation baked in; colour converted to sRGB or profile kept
Layout Every <img> has width and height or a CSS aspect-ratio
Priority LCP image has fetchpriority="high" and no loading="lazy"; below-the-fold images are lazy
Caching Fingerprinted file names with a one-year immutable cache; Vary: Accept if negotiating formats
Verification Lighthouse image audits pass; LCP under 2.5 s and CLS under 0.1 in the field

Try it: Batch Image Resizer for the dimensions row, then Batch Image Compressor for the compression row.

Run through it once per template rather than once per image, and images will stop being the problem on your pages that they are on almost everyone else's.

Sources and further reading

About the author

HelpMeJPG editorial teamEditorial team

The people who build and maintain the HelpMeJPG tools. Guides are written from the tools' own behaviour and the standards they implement, and are revised whenever a tool changes.