Skip to main content
KadiCache
Engineering Journal · Core Web Vitals9 min read1,821 wordsVerified 2026-11-23

WordPress Images: WebP vs AVIF, srcset & Hero LCP

Optimize WordPress images in 2026: WebP vs AVIF decoding math, responsive srcset tuning, and why lazy-loading hero images ruins LCP.

1.8 MB JPEG converted into 42 KB AVIF and WebP smartphone hero image achieving 1.1s LCP
0.000 Layout Shift11 Sections✓ Verified
⚡ Executive Summary · 30-Second Spec100% Code-Verified
WP Admin Path
WP Admin -> KadiCache -> Images + Lazyload + Core Web Vitals
Measured Impact
55%–78% Smaller Image Payloads · -600 ms Mobile Hero LCP
DevTools Proof Marker
fetchpriority="high" | loading="lazy" skipped on hero | .webp
  • Images account for 55%–75% of total page weight on WooCommerce and editorial WordPress sites—and make up the Largest Contentful Paint (LCP) element on over 72% of mobile pages.
  • Putting loading="lazy" on your above-the-fold hero banner or first product gallery image delays LCP by 500 ms to 1,200 ms because the browser waits for CSS layout before even requesting the image!
  • Even if you convert JPEGs to WebP or AVIF, missing or inaccurate sizes="..." attributes routinely trick a 390px iPhone into downloading a 1920px desktop banner.
Table of Contents (11 sections)

Optimizing WordPress images in 2026 requires looking past file-size compression percentages alone. We routinely audit WooCommerce stores where every single product photo was already compressed to WebP—yet mobile Largest Contentful Paint (LCP) still sat at 4.3 seconds and Cumulative Layout Shift (CLS) failed at 0.19 because of three markup mistakes: lazy-loading the hero image, serving 2048px srcset files to 390px phones, and omitting intrinsic dimensions.

WebP vs AVIF vs Legacy JPEG/PNG: Real Byte & Decode Trade-Offs#

Modern browsers support both WebP (97.8%+ global support) and AVIF (93.5%+ global support). How do they actually compare across real WordPress asset types when measuring both network transfer time and mobile CPU decode latency?

Image Asset CategoryOriginal JPEG / PNGLossy WebP (q=82)AVIF (q=62)Best Engineering Choice for WordPress
Hero Lifestyle Photograph (1600×900)340 KB JPEG78 KB (-77%)61 KB (-82%)WebP (universal, ultra-fast decode) or AVIF w/ WebP fallback
WooCommerce Studio Product (1000×1000)185 KB JPEG39 KB (-79%)33 KB (-82%)Lossy · Balanced WebP (preserves fabric/packaging texture)
UI Screenshot / Sharp Text Diagram (1440×920)490 KB PNG84 KB Lossless/Near-Lossless WebP110 KB (chroma subsampling blurs 1px borders unless 4:4:4)Lossless · Exact WebP (2x Retina crispness, 0 ringing!)
Brand Logo / UI Icons28 KB PNG9 KB WebP8 KB AVIFInline / File SVG (1–3 KB, infinite resolution!)

Notice row 3: on crisp UI screenshots, typography banners, and technical diagrams, standard 4:2:0 AVIF encoders soften red/blue 1px edges unless tuned carefully, whereas WebP delivers both tiny lossy photographs and razor-sharp lossless UI graphics with fast hardware/SIMD decoding on every iPhone, Android, and desktop browser on earth.

FIG 01Cloud WebP conversion with segmented compression modes, synced quality slider, and non-destructive local publication.Zoom 2x

Why Lazy-Loading Your Hero Image Destroys Mobile LCP (+700 ms Penalty)#

Open Chrome's networking internals and trace what happens during the first 300 milliseconds of loading a WordPress page:

  1. With Eager + fetchpriority="high" (Fast Path): As soon as the first 14 KB TCP packet of HTML arrives, Chrome's lightweight HTML Preload Scanner spots <img src="hero.webp" fetchpriority="high"> (or <link rel="preload" as="image" fetchpriority="high">) and starts downloading hero.webp at Highest priority in parallel with <head> stylesheets!
  1. With loading="lazy" on the Hero (Broken Path): Seeing loading="lazy", the HTML Preload Scanner skips the image completely! Chrome downloads all CSS, builds the DOM and CSSOM, executes synchronous <head> scripts, computes full page layout geometry, discovers "Oh! This image actually sits at Y = 120px inside the viewport!", and only then queues the network request! On 4G mobile, waiting for CSS + Layout before starting the hero download adds 550 ms to 1,200 ms of pure Resource Load Delay.

Why WordPress Core's Automatic fetchpriority Heuristic Often Guesses Wrong#

WordPress 6.3+ added an internal wp_get_loading_optimization_attributes() counter that tries to omit loading="lazy" and add fetchpriority="high" on the first large content image. On real commercial sites, three things defeat that core heuristic:

  • Header Mega-Menu Promotional Thumbnails: If your navigation mega-menu contains a 350×350 featured-post thumbnail inside <header> (hidden until hover!), it appears earlier in HTML order than <main>, stealing the fetchpriority="high" slot while your real hero banner gets loading="lazy"!
  • Separate Desktop vs Mobile Hero Banners: Many Elementor and Gutenberg templates hide .desktop-hero-img (display: none below 768px) and show .mobile-hero-img on phones. WordPress Core cannot run CSS media queries in PHP, so it prioritizes the hidden desktop image on mobile!
  • CSS background-image Heroes: Core image filters never see hero images defined inside container CSS backgrounds.

Look at how KadiCache solves all three cases across Free Core and Cloud Pro:

  • Free Core (Optimization/ImageLazyOptimizer.php & ImageContainerClassifier.php): Classifies header/nav/logo/hero containers conservatively so above-the-fold candidates stay eager while offscreen catalog grids, footer badges, and below-the-fold CSS backgrounds (BackgroundLazyOptimizer.php) lazy-load cleanly.
  • Cloud Pro (Improve LCP): Detects the true visible mobile LCP element and desktop LCP element separately, strips loading="lazy", sets fetchpriority="high", demotes competing hidden hero images, and injects viewport-matched <link rel="preload" as="image" imagesrcset="..." imagesizes="..." fetchpriority="high"> in <head>.
FIG 02Lazy-load offscreen images, CSS backgrounds, and YouTube embeds while injecting missing width/height dimensions.Zoom 2x

Fixing Broken srcset & sizes Attributes on WooCommerce Grids#

Even when WordPress generates 6 responsive image sizes (thumbnail 150w, medium 300w, medium_large 768w, large 1024w, 1536x1536, 2048x2048), browsers pick which file to download from srcset based entirely on the sizes attribute—before reading your CSS!

Look at WordPress's default fallback sizes attribute when a theme does not customize wp_calculate_image_sizes:

HTML
<!-- Default WordPress fallback sizes: tells mobile OK, tells desktop a 300px card is 100vw wide! -->
<img src="shoe-1024x1024.webp"
     srcset="shoe-300x300.webp 300w, shoe-768x768.webp 768w, shoe-1024x1024.webp 1024w"
     sizes="(max-width: 1024px) 100vw, 1024px"
     width="1024" height="1024" alt="Running shoe">

On a 4-column desktop shop grid (1440px screen, 2x Retina DPR), each product card is only 310 CSS pixels wide (620 device pixels). Yet sizes="1024px" tells a 2x MacBook Retina display it needs 1024 × 2 = 2048px, forcing Chrome to download the massive 1536w or 2048w file for all 16 product cards!

Fix custom theme archive grids with a clean wp_calculate_image_sizes filter (or WordPress 6.7+ sizes="auto" on lazy-loaded images):

PHP
// Accurate sizes attribute for a 4-column desktop / 2-column mobile WooCommerce archive grid
add_filter('wp_calculate_image_sizes', function (string $sizes, $size): string {
    if (function_exists('is_shop') && (is_shop() || is_product_category() || is_product_tag())) {
        return '(max-width: 640px) 48vw, (max-width: 1024px) 31vw, 310px';
    }
    return $sizes;
}, 10, 2);

Changing 1024px to 310px on a 24-product category archive cuts total image bytes downloaded on Retina laptops and tablets by 65% to 78% immediately (clearing Lighthouse's Properly size images warning).

Preventing Image CLS With Automatic Dimension Resolution (ImageDimensionResolver.php)#

Page-builder HTML blocks, custom ACF templates, and SVG icons frequently output <img src="..."> with no width or height attributes. Without dimensions, the browser reserves 0×0 pixels during initial layout and pushes all surrounding text down the instant the image header decodes.

Enabling Add Missing Image Dimensions inside WP Admin -> KadiCache -> Lazyload activates Optimization/Images/ImageDimensionResolver.php:

  • Resolves exact pixel dimensions for local uploads and SVGs (kadicache_image_dimensions), injecting width, height, and intrinsic CSS variables (--kc-cis, --kc-ar).
  • Automatically invalidates stale dimensions (ImageLazyOptimizer::invalidateDimensions()) whenever _wp_attachment_metadata updates!
FIG 03Fine-grain Improve LCP page exclusions let site owners bypass local real-browser hero preloading per route.Zoom 2x

4-Point Verification for WordPress Images#

  1. DevTools -> Elements (Hero <img>): Confirm fetchpriority="high", explicit width + height, .webp source, and zero loading="lazy".
  2. DevTools -> Network -> Img: Reload on Mobile (390×844) and confirm below-the-fold product images do not download until you scroll.
  3. Check currentSrc vs Displayed Size: Run [...document.images].map(i => ({ src: i.currentSrc.split("/").pop(), natural: i.naturalWidth, rendered: Math.round(i.clientWidth * devicePixelRatio) })) in Console to spot any oversized banner.
  4. Check Scroll CLS: Scroll top-to-bottom and confirm 0.000 layout shift across every lazy-loaded gallery.

Responsive Art Direction With <picture> (Solving Desktop vs Mobile Hero Bloat)#

Earlier we noted a classic Elementor and Gutenberg anti-pattern: rendering two separate <img> tags inside the hero (.hide-on-mobile 1920×800 landscape banner + .hide-on-desktop 800×1000 portrait banner). Why is that dangerous? Because browsers often start preloading the hidden display: none <img> tag before external CSS finishes downloading—wasting bandwidth and confusing LCP prioritization!

Whenever your mobile hero uses a different crop or aspect ratio (4:5 portrait on phones vs 21:9 widescreen on desktop), use a single standard HTML <picture> element with explicit per-source width and height attributes:

HTML
<!-- Zero duplicate downloads, zero CLS across both portrait mobile AND landscape desktop! -->
<picture>
  <source media="(max-width: 767px)"
          srcset="/uploads/hero-mobile-480w.webp 480w, /uploads/hero-mobile-780w.webp 780w"
          sizes="100vw"
          width="780" height="960" type="image/webp">
  <img src="/uploads/hero-desktop-1600w.webp"
       srcset="/uploads/hero-desktop-1200w.webp 1200w, /uploads/hero-desktop-1920w.webp 1920w"
       sizes="100vw"
       width="1600" height="680"
       fetchpriority="high" decoding="sync"
       alt="Spring espresso equipment collection">
</picture>

Every modern browser evaluates <source media="(max-width: 767px)"> inside the HTML Preload Scanner at byte zero:

  • Phones download only hero-mobile-780w.webp (36 KB) and reserve a 780:960 aspect ratio immediately (0.000 CLS!).
  • Desktop monitors download only hero-desktop-1600w.webp (74 KB) and reserve a 1600:680 aspect ratio immediately!

decoding="sync" vs decoding="async": When Each Attribute Wins#

WordPress Core adds decoding="async" to almost every <img> tag by default. What does decoding="async" actually tell the browser, and should it stay on your hero LCP image?

Image Position in PageRecommended loadingRecommended fetchpriorityRecommended decodingEngineering Reason
Above-the-Fold Hero LCP ImageOmit (eager default)highsync (or auto)Prevents Chrome from painting text Frame 1 without the hero and delaying LCP by 1–2 frames
Header Brand Logo (<svg> / WebP)Omit (eager default)autosyncAvoids empty logo flicker in top navigation bar
Below-the-Fold Product Grid (Cards 5–24)lazyauto / lowasyncDecodes compressed WebP bitmaps off the main thread during scroll (0 ms jank!)
Hidden Carousel Slides 2, 3, 4lazylowasyncStops offscreen slides from stealing hero bandwidth!

Look at row 4: offscreen hero carousel slides (Slide 2, Slide 3, Slide 4) are one of the sneakiest LCP thieves in WordPress! When a homepage slider loads four 1600px banners eagerly at once, Slides 2, 3, and 4 split mobile 4G bandwidth 4 ways—making Slide 1 (your real LCP!) finish 3x slower! KadiCache's Pro Local Improve LCP automatically prioritizes the visible Slide 1 hero while demoting competing slides.

Rewriting CSS background-image Assets Into WebP & Lazy Backgrounds#

Many themes still attach decorative section textures, callout banners, and testimonial backdrops via CSS background-image: url("/wp-content/uploads/2026/banner.jpg"). Standard WordPress <picture> WebP plugins completely miss images inside .css files and inline style="" attributes!

  • In Free Core (Optimization/BackgroundLazyOptimizer.php & CssBackgroundSelectorMatcher.php): KadiCache defers below-the-fold CSS background-image downloads until the container approaches the viewport.
  • In Cloud Pro (Cloud WebP Image Optimization): KadiCache rewrites <img>, responsive srcset, and CSS background-image URLs into optimized WebP files while preserving your original JPEG/PNG uploads on disk for instant 1-click restoration.

Disabling Redundant Intermediate WordPress Thumbnail Sizes & Locking aspect-ratio#

Every time an editor uploads one product photo, a typical theme + WooCommerce + page-builder install generates 11 to 19 cropped derivative files in wp-content/uploads/. Audit registered sizes with wp media image-size over SSH: removing unused legacy slider sizes saves gigabytes of NVMe backup storage while keeping standard 300w, 600w, 768w, 1024w, and 1536w srcset steps intact. Pair clean thumbnail tiers with CSS aspect-ratio: 1 / 1 (or KadiCache's automatic --kc-ar injection) and watch real-user CrUX p75 LCP and CLS turn permanently green across your entire catalog.

Stripping Camera EXIF & Color-Profile Bloat Safely#

Smartphone product photos uploaded directly by store staff frequently carry 35 KB to 90 KB of hidden GPS EXIF metadata, embedded Canon/Sony preview thumbnails, and oversized CMYK/Display-P3 ICC profiles inside a 60 KB visual image! Converting uploads to sRGB Lossy WebP inside KadiCache Cloud Image Optimization strips non-display EXIF baggage automatically while keeping original high-resolution master files untouched inside wp-content/uploads/ whenever print or press downloads need them later.

Frequently Asked Engineering Questions

Is AVIF always faster than WebP for hero LCP images on mid-range mobile phones?
Not always! AVIF achieves 15%–22% smaller file sizes than WebP on photographic gradients, which helps over slow 3G/4G networks. However, software AVIF decoding on budget Android CPUs without hardware AV1 decoders takes slightly more CPU time than WebP, and high-resolution lossless crisp UI graphics often encode faster and cleaner in WebP. Both formats beat legacy JPEG/PNG by 50%–75%.
Doesn’t WordPress 6.3+ automatically add fetchpriority="high" to the right LCP image?
WordPress Core uses a simple server-side counter heuristic during the_content that frequently guesses wrong—putting fetchpriority="high" on a tiny header logo, author avatar, or hidden desktop banner while your actual mobile Elementor/WooCommerce hero image sits further down in markup or inside a CSS background!
What happens if I replace an image in the WordPress Media Library after KadiCache cached its width and height?
Look at ImageLazyOptimizer::invalidateDimensions() (lines 66–80): KadiCache hooks added_post_meta, update_post_meta, and delete_post_meta on _wp_attachment_metadata, invalidating cached intrinsic dimensions immediately so regenerated thumbnails never stretch or distort.
Does KadiCache Cloud WebP conversion overwrite or delete my original JPEG/PNG files in wp-content/uploads/?
Never. Originals in your WordPress Media Library remain 100% untouched on disk, and you can restore original image delivery with a single click inside WP Admin -> KadiCache -> Images.
Verified WordPress Architecture · Core Web Vitals
Apply these exact optimizations on your WordPress or WooCommerce site in 2 minutes.
E-E-A-T Source Verified

Creator of KadiCache’s Early PHP Drop-In, 7-Driver Object Cache Engine, Cloud Remove Unused CSS, and Zero-CLS Lazy Render pipeline.

Optimization/ImageLazyOptimizer.phpOptimization/Images/ImageDimensionResolver.phpOptimization/Images/ImageContainerClassifier.phpOptimization/BackgroundLazyOptimizer.php
Connected Topical Cluster · Continue Deepening Your Setup