Skip to content

Image Optimisation for Fast Websites

Web Development6 min read

How to make website images load fast: pick formats, size and compress properly, use srcset, lazy loading and a CDN, and protect Core Web Vitals.

In this article
  1. Why images matter so much
  2. Step 1: Resize to the display size
  3. Step 2: Choose the right format
  4. Step 5: Load and deliver images at the right moment
  5. Measure and set a budget
  6. What to do next

To make images load fast, serve each one at the size it is displayed, in a modern format such as AVIF or WebP with a fallback, compressed to the lowest quality that still looks right, with explicit dimensions, lazy loading below the fold and caching headers or a CDN in front. Images are often the heaviest part of a page, so fixing them usually improves speed more than any code change. Better image handling also helps Core Web Vitals, mobile data use and accessibility. This guide gives you the checklist in the order that tends to pay off.

Why images matter so much

On most marketing sites, shops and blogs, images account for a large share of the bytes downloaded. A heavy hero photo delays the Largest Contentful Paint (LCP), an image without dimensions shifts the layout and raises Cumulative Layout Shift (CLS), and dozens of unoptimised thumbnails drain mobile data. Visitors on a train or in a rural area notice immediately. If you are not familiar with the metrics, start with our explainer on Core Web Vitals.

The aim is not the smallest possible file. It is the smallest file that still looks good at its real display size on the device in front of the visitor.

Step 1: Resize to the display size

The most common mistake is uploading a 4000-pixel-wide photo and showing it in a 600-pixel slot. The browser downloads every pixel, then throws most away.

  1. Find the largest width at which the image is ever displayed.
  2. Allow for high-density screens: a 600 CSS pixel slot may need a 1200 pixel file for a 2x display.
  3. Produce several sizes, for example 400, 800, 1200 and 1600 pixels wide, and let the browser choose.
  4. Crop to the aspect ratio you actually use, rather than hiding the rest with CSS.

Automate this. Doing it by hand for every upload does not last, so use a build step, a CMS image pipeline or an image service. If you use a headless CMS, check whether it can generate sized variants for you.

Step 2: Choose the right format

Format choice is about matching the tool to the content. A logo saved as a photo format looks soft and weighs more than the same logo as SVG, while a photograph saved as PNG can be several times larger than a well-compressed AVIF or WebP.

FormatBest forNotes
AVIFPhotos and complex imagesOften the smallest files, slower to encode, check browser support
WebPPhotos and graphicsWidely supported, good all-round choice
JPEGPhotos, universal fallbackWorks everywhere, larger files
PNGGraphics needing lossless quality or transparencyLarge for photos, so avoid them there
SVGLogos, icons, simple illustrationsScales perfectly and is tiny, but sanitise untrusted files
GIFRarely the best choiceUse a short muted video or animated WebP instead

Browser support changes, so confirm current support on MDN before relying on a format. The safe pattern is to offer modern formats first with a fallback:

<picture>
  <source srcset="hero.avif" type="image/avif">
  <source srcset="hero.webp" type="image/webp">
  <img src="hero.jpg" width="1200" height="630" alt="Describe the image">
</picture>

Step 3: Compress sensibly

Compression is a trade between size and quality. Lossy formats let you dial it.

  • Start with a moderate quality setting and compare the result with the original at actual display size, not zoomed in.
  • Photos tolerate more compression than text or sharp graphics, which show artefacts quickly.
  • Strip unnecessary metadata, such as camera details. Remove location data from photos of people or premises before publishing, which is also a privacy point.
  • Use a tool that can be repeated in a pipeline, so the quality is consistent across the site.

Avoid compressing an already compressed JPEG several times, as quality degrades with each pass. Keep the original source files safely stored and generate the web versions from them.

Step 4: Serve responsive images

With srcset and sizes, the browser picks the best file for the screen width and density.

<img
  src="card-800.webp"
  srcset="card-400.webp 400w, card-800.webp 800w, card-1200.webp 1200w"
  sizes="(min-width: 900px) 33vw, 100vw"
  width="800" height="533"
  alt="Describe the image">

The sizes attribute tells the browser how wide the image will be in the layout before CSS is loaded, so write it to match your real layout. Use the picture element when you need different crops for different screens, a practice known as art direction. A mobile-first approach to layout, as described in mobile-first responsive design principles, makes these decisions easier.

Step 5: Load and deliver images at the right moment

  • Always set width and height (or a CSS aspect-ratio) so the browser reserves space and avoids layout shift.
  • Lazy-load below the fold with loading="lazy", and add decoding="async" to keep the main thread free.
  • Do not lazy-load the main image. For the hero or other likely LCP image, load it eagerly and consider fetchpriority="high". Preloading can help in some cases, but test it, since over-prioritising wastes bandwidth.
  • Avoid CSS background images for content. The browser discovers them later and they cannot use srcset easily.
  • Use placeholders such as a dominant colour or a tiny blurred preview if the design benefits, but keep them light.

Your rendering approach affects when images are discovered. Server-rendered pages show image tags in the first HTML, while client-rendered pages may delay discovery until scripts run. Our guide to SSR, SSG and client-side rendering explains why.

Step 6: Cache and deliver efficiently

  1. Give images long-lived cache headers and use fingerprinted file names, so browsers keep them until the file really changes.
  2. Serve over HTTP/2 or HTTP/3 and compress other assets, though images themselves are already compressed.
  3. Consider an image CDN or hosting platform that resizes and converts on request and caches results near visitors.
  4. Keep images on the same origin or a well-configured domain to avoid extra connection setup, and check privacy and data-transfer implications if you use a third-party service. This is not legal advice; for GDPR questions about third-party services, consult current guidance from the Data Protection Commission (DPC) or a qualified adviser.

Do not forget accessibility and quality

Fast images should still be useful to everyone. Write meaningful alt text for content images and empty alt text for purely decorative ones, avoid putting important text inside images, and check contrast where text sits on a photo. These points are covered in our overview of web accessibility basics for developers.

Measure and set a budget

  • Run Lighthouse or PageSpeed Insights and check the "properly size images", "serve images in next-gen formats" and "defer offscreen images" hints.
  • Look at real-user data in your analytics or the Chrome User Experience Report where available, since lab tests do not capture every device.
  • Sort the network panel by size and fix the biggest files first.
  • Set an image budget for each page type and fail the build, or at least raise a warning, when a new upload breaks it.

What to do next

You do not need to fix everything at once. A handful of well-chosen changes on your busiest pages will usually show up in your measurements quickly.

  1. Identify the three heaviest images on your most visited pages.
  2. Resize them, convert to a modern format and add width and height.
  3. Make sure your hero image is not lazy-loaded and below-the-fold images are.
  4. Automate resizing and conversion in your build or CMS.
  5. Re-test Core Web Vitals and record the baseline.

If you would like help with this, the CloudWiss team in Dublin can talk it through, from a quick review of your current pages to a full performance pass. You can read more about our web application development service to see how performance is usually handled in a build.

Share this article

General educational information, not legal or professional advice for your specific situation.

Frequently asked questions

Which image format should I use in 2026?

There is no single answer. AVIF and WebP usually give smaller files than JPEG or PNG for photos, SVG suits logos and icons, and JPEG or PNG remain useful fallbacks. Check current browser support on MDN and serve the best format each browser can handle.

Should every image be lazy-loaded?

No. Images below the fold benefit from lazy loading, but the main image at the top of the page, often the Largest Contentful Paint element, should load promptly and not be lazy-loaded. Lazy-loading it usually makes the page feel slower.

How small should an image file be?

It depends on the image and its purpose, so there is no honest universal number. Set a budget for your page, check the heaviest images first, and compress until quality loss becomes visible, then step back slightly.

Do I need a CDN for images?

Not always, but an image CDN or a hosting platform with image transformation can resize, convert and cache images for you. This saves manual work and serves files from locations nearer to your visitors, which matters for audiences across Ireland and the EU.

Keep reading

Let’s build it

Ready to build with CloudWiss?

Tell us what you want to build, move to the cloud or keep running. We reply with a clear next step.