How to Fix Next-Gen Image Formats: Serve WebP and AVIF

This check flags homepage images over 20 KB that are delivered as JPEG, PNG or GIF instead of a modern format like WebP or AVIF. By the end of this guide you will have converted those images, served them with safe fallbacks through HTML or your CDN, and confirmed that browsers receive the smaller files.

By Updated ⏱ 1-2 hours🎯 Intermediate● Medium impactTechnical
Illustration: Next-gen image formats fix guide
TECHNICAL · FIX GUIDE Next-gen image formats IMPACTEFFORT TIME1-2 hours LEVELIntermediate

Why it matters

Images are usually the heaviest part of a homepage, and the hero image is often the Largest Contentful Paint element. WebP is typically 25-35% smaller than an equivalent JPEG, and AVIF is often 40-50% smaller. That reduces load time on mobile connections, can improve LCP in Core Web Vitals (a ranking signal), lowers bandwidth costs, and makes pages cheaper for crawlers and AI fetchers to retrieve.

✕Beforehttps://example.com/images/hero.jpg isserved with Content-Type: image/jpegat 412 KB.✓AfterThe same hero is served as image/avifat 96 KB, with a JPEG fallback onlyfor browsers that cannot decode AVIF.

What you need

Access to your site's image files, CMS media library or theme templates
An image converter: Squoosh (squoosh.app), cwebp/avifenc command-line tools, or the sharp Node.js library
Access to your CDN or server config if you plan to convert automatically
Chrome or Firefox DevTools

Step-by-step fix

1

List the homepage images that get flagged

Open your homepage in Chrome, press F12, go to the Network tab, choose the Img filter and reload with cache disabled. Sort by Size and note every request whose Type is jpeg, png or gif and whose transferred size is above 20 KB. SVGs and images under 20 KB are not flagged, so you can skip them.

Also check the Content-Type response header, because the check uses the served type, not the file extension.

Pro tip: Add the 'Type' column via right-click on the Network column headers if it is hidden.
2

Convert the images to WebP and AVIF

Create a WebP and an AVIF version of each flagged image, keeping the original as a fallback. For a handful of files, Squoosh in the browser is enough. For batches, use the command-line encoders or sharp.

Quality around 75-80 for WebP and 50-60 for AVIF usually looks identical to the source at a fraction of the size.

text
# WebP (libwebp)
cwebp -q 80 hero.jpg -o hero.webp

# AVIF (libavif)
avifenc --min 20 --max 35 -s 6 hero.jpg hero.avif

# Batch with sharp (Node.js)
npx sharp-cli -i 'images/*.{jpg,png}' -o images/ -f webp -q 80
npx sharp-cli -i 'images/*.{jpg,png}' -o images/ -f avif -q 55
Pro tip: Resize at the same time. A 4000 px wide photo shown at 1200 px wastes more bytes than the format does.
3

Serve modern formats with a <picture> fallback

Wrap each flagged <img> in a <picture> element. The browser picks the first <source> whose type it supports and falls back to the <img> otherwise. Keep width, height and alt on the <img>, since that is the element that is rendered and measured.

Do not lazy-load the hero image; give it fetchpriority="high" instead.

html
<picture>
  <source srcset="/images/hero.avif" type="image/avif">
  <source srcset="/images/hero.webp" type="image/webp">
  <img src="/images/hero.jpg" alt="Example Co workshop team" width="1200" height="630" fetchpriority="high">
</picture>
Pro tip: Order matters: list AVIF before WebP, or browsers that support both will take WebP.
4

Or let your CDN or server convert automatically

If you cannot edit every template, negotiate the format on the server from the browser's Accept header. Image CDNs do this with a parameter (imgix auto=format, Cloudinary f_auto, Cloudflare Images transformations format=auto). webp` files next to the originals and serve them when the browser accepts WebP.

Always send Vary: Accept so caches don't serve WebP to browsers that cannot read it.

nginx
# http block
map $http_accept $webp_suffix {
    default "";
    "~*image/webp" ".webp";
}

# server block (expects hero.jpg.webp next to hero.jpg)
location ~* ^/images/.+\.(png|jpe?g)$ {
    add_header Vary Accept;
    try_files $uri$webp_suffix $uri =404;
}
Pro tip: After enabling server-side conversion, purge your CDN cache, otherwise old JPEG responses keep being served.
5

Make sure the server sends the right Content-Type

webp served as application/octet-stream or image/jpeg will still fail, and some browsers will refuse to render it. Confirm your server maps the extensions to the correct MIME types. types; add them if missing.

htaccess or the vhost.

apache
# Apache (.htaccess)
AddType image/avif .avif
AddType image/webp .webp

# Nginx (mime.types, inside types { })
image/avif avif;
image/webp webp;
6

Handle CSS backgrounds and animated GIFs

Background images set in CSS are not covered by <picture>. Use image-set() to offer AVIF and WebP with a JPEG fallback. Large animated GIFs are best replaced with a muted, looping MP4/WebM <video>, or converted to animated WebP, which is typically far smaller.

text
.hero {
  background-image: url("/images/hero.jpg");
  background-image: image-set(
    url("/images/hero.avif") type("image/avif"),
    url("/images/hero.webp") type("image/webp"),
    url("/images/hero.jpg") type("image/jpeg")
  );
}
Pro tip: Convert a GIF to animated WebP with: gif2webp -q 75 banner.gif -o banner.webp
7

Check the result in the browser

Reload the homepage with DevTools open, cache disabled, on the Network > Img filter. Every image above 20 KB should now show Type webp or avif. Click one and confirm the Content-Type response header matches.

Then run Lighthouse and confirm the image-format savings opportunity no longer lists your homepage images, and re-run the audit.

text
curl -sI -H "Accept: image/avif,image/webp,*/*" https://example.com/images/hero.jpg | grep -i -E "content-type|vary"

Platform-specific notes

WordPress

WordPress supports WebP uploads and, since 6.5, AVIF uploads (if the server's GD or Imagick supports it). Install the official 'Modern Image Formats' plugin (from the Performance team) and choose WebP or AVIF under Settings > Media to generate modern versions on upload. It applies to new uploads; use the plugin's or WP-CLI regeneration to convert existing images. Images hard-coded in theme files still need manual <picture> markup.

Shopify

Images rendered through the image_url and image_tag Liquid filters are served from Shopify's CDN, which automatically delivers WebP or AVIF to supporting browsers. Flagged images are usually ones loaded with asset_url or file_url, or pasted as full URLs in rich text. Move them into the media/Files area and render them with {{ image | image_url: width: 1200 | image_tag }}.

Wix

Images uploaded to the Wix Media Manager are converted and served as WebP or AVIF automatically. Flags usually come from images embedded via custom HTML/iframe elements or external URLs; re-upload those through the Media Manager instead.

Webflow

In the Assets panel, select images and use the convert option to switch them to WebP or AVIF; Webflow updates references across the site. Images set as background images in the Designer and assets on custom code embeds need to be converted and replaced manually.

Next.js

The next/image component serves WebP by default through the image optimizer. To add AVIF, set images: { formats: ['image/avif', 'image/webp'] } in next.config.js. Plain <img> tags and CSS backgrounds bypass the optimizer, so switch them to <Image> or convert the files yourself. On static exports (output: 'export') the default optimizer is unavailable; use a custom loader or pre-converted files.

Check that it worked

✅ How to verify

  • In DevTools Network (Img filter, cache disabled), every homepage image over 20 KB shows Type webp or avif.
  • curl -sI with an Accept header containing image/avif or image/webp returns the matching Content-Type and a Vary: Accept header for negotiated URLs.
  • Lighthouse no longer lists homepage images under 'Serve images in next-gen formats' or the image delivery insight.
  • Re-run the audit and confirm the Next-gen image formats check passes.

⚠️ Common mistakes

  • Renaming .jpg files to .webp without re-encoding them, so the server still sends JPEG bytes or a mismatched Content-Type.
  • Enabling server or CDN negotiation without Vary: Accept, causing a cache to serve WebP to clients that requested JPEG (or the reverse).
  • Converting only the <img> tags and forgetting CSS background images, theme assets and animated GIF banners, which are often the largest files.
  • Putting the WebP <source> before AVIF, so browsers that support both never receive the smaller AVIF file.

Is this still an issue on your site? Run a free audit — ZORO checks this and 294 other SEO, AI-visibility, accessibility and security signals, with fixes for your platform.

Check my site free

FAQ

Should I use WebP or AVIF?

Use both when you can: AVIF first for the smallest files, WebP as the second choice. All current versions of Chrome, Edge, Firefox and Safari decode both. If you only produce one, WebP encodes faster and is supported almost everywhere; AVIF gives bigger savings on photos.

Do I still need JPEG or PNG fallbacks in 2026?

Browser support is near universal, but keeping the original as the <img> src costs nothing and protects older browsers, email clients and some social preview scrapers. For Open Graph images, keep JPEG or PNG, since not every platform renders WebP or AVIF previews.

Does switching to WebP improve SEO?

Not directly; Google does not rank a page higher for the file format itself. The benefit comes from smaller pages and faster Largest Contentful Paint, which feed into Core Web Vitals and user experience. Google Images indexes WebP and AVIF normally.

Why is an image still flagged after I converted it?

Usually the old file is still referenced somewhere (CSS, a theme setting, a page builder block), the CDN is serving a cached JPEG, or the server sends the wrong Content-Type. Check the actual request in DevTools, purge the CDN cache and confirm the response header reads image/webp or image/avif.