Image Lazyload, Hero LCP Protection & Missing Width/Height Injection
Defer below-the-fold <img> and <picture> tags while automatically keeping above-the-fold hero images eager and injecting missing width/height attributes across images and SVGs.
- Defers below-the-fold
<img>and<picture>downloads (ImageLazyOptimizer.php) so mobile bandwidth focuses 100% on visible above-the-fold content. - Automatically keeps logos,
<header>graphics, and above-the-fold hero images eager (ImageContainerClassifier.php) so Largest Contentful Paint (LCP) is never penalized. - Resolves intrinsic pixel dimensions from local image headers and SVG
viewBoxattributes (ImageDimensionResolver.php), injecting missingwidthandheightattributes to prevent image layout shifts. - Supports filename, CSS class (
.no-lazy,.skip-lazy), page-path, and per-post Gutenberg exclusions.
How Image Lazyload & Dimension Injection Protect Both LCP and CLS#
On a typical WooCommerce shop category or long-form blog tutorial containing 45 images, only 2 to 4 images actually appear inside the visitor’s initial mobile screen (390 × 844 px). Downloading all 45 images eagerly on page load wastes 2 MB to 6 MB of cellular bandwidth and starves your critical hero image of network throughput.
At the same time, two classic mistakes in basic WordPress lazy-loading snippets damage Core Web Vitals:
- Accidentally Lazyloading the Hero Image: If your above-the-fold banner carries
loading="lazy", Chrome waits until layout completes before even queuing the hero image download—adding450 – 900 msto mobileLCP! - Leaving
<img>Tags Withoutwidth&height: Theme templates, custom shortcodes, and page-builder HTML widgets frequently output<img src="/uploads/feature.png">with no pixel dimensions. Before a lazy-loaded image downloads, the browser assumes its height is0 px—and when the user scrolls down and the image arrives, the paragraph below jumps400 pxdownward (CLS > 0.15)!
KadiCache Free Core (ImageLazyOptimizer.php, ImageContainerClassifier.php, and ImageDimensionResolver.php) solves both sides automatically inside WP Admin -> KadiCache -> Lazyload.
Inside ImageContainerClassifier.php: Automatic Above-the-Fold Protection#
Before ImageLazyOptimizer.php adds lazy-loading to any <img> or <picture> element, ImageContainerClassifier.php inspects the tag and its surrounding HTML structure:
| Image Context Detected in HTML | ImageLazyOptimizer Decision | Why It Matters |
|---|---|---|
Header & Brand Logos (<header>, .custom-logo, .site-logo) | Kept Eager (Immediate) | Brand identity paints on the very first frame |
| Above-the-Fold Hero & First Product Gallery Image | Kept Eager (Immediate) | Avoids Lighthouse LCP image was lazily loaded penalty |
Explicit Priority Attributes (fetchpriority="high", loading="eager") | Kept Eager (Immediate) | Honors WordPress core & Pro Local Improve LCP hints |
Tracking Pixels & <noscript> Fallbacks (1×1 pixels, <noscript>) | Left Untouched | Preserves analytics beacons and non-JS crawler markup |
| Below-the-Fold Content, Grid & Footer Images | loading="lazy" + decoding="async" | Defers download & offloads image decoding off the main thread |
Inside ImageDimensionResolver.php: Fixing Unsized images Across Raster & SVG Files#
Enabling Add missing image dimensions (image_dimensions_enabled) scans <img> tags that are missing either width or height (while skipping tags that already define both attributes or inline aspect-ratio styles):
- Local JPEG, PNG, WebP, GIF & AVIF Uploads: Reads lightweight image header metadata from local files inside
wp-content/(caching dimensions in memory/transients so disk I/O happens once, never on repeat hits) and injects exact integerwidth="..."andheight="..."attributes. - Vector
.svgLogos & Icons: Parses the SVG root<svg width="..." height="..." viewBox="0 0 W H">coordinates cleanly so vector icons reserve their exact aspect ratio instead of collapsing to0 × 0or flashing full-width before CSS loads! - Responsive Fluid CSS Compatibility: Modern WordPress CSS (
img { max-width: 100%; height: auto; }) uses the injected HTMLwidthandheightattributes purely to compute the intrinsic aspect ratio (width / height) prior to download—your responsive images still scale fluidly across every screen size!
Configuring Image & Page Exclusions#
If a custom above-the-fold slider or JavaScript gallery plugin needs a specific image kept eager manually:
- Excluded Image Files (
lazy_excluded_images): Expand the drawer inWP Admin -> KadiCache -> Lazyloadand enter one filename (hero-slide-2.webp), CSS class (skip-lazy), or path fragment (/uploads/2026/11/featured-banner) per line. - Excluded Lazyload Page Paths (
lazy_excluded_paths): Bypass lazy-loading on specific routes (/print-catalog/*), or check Disable: Lazy load inside the Gutenberg sidebar (Per-Page Exclusions). - HTML Attribute / Class Opt-Outs: KadiCache honors
data-no-lazy,skip-lazy, andno-lazyclasses natively in theme templates.
WooCommerce Product Grids, Variation Galleries & AJAX Filters#
High-catalog WooCommerce storefronts introduce three dynamic image workflows that break fragile JavaScript lazy-loaders—and why KadiCache relies on standards-compliant HTML attributes instead:
- AJAX Faceted Product Filters (FacetWP, Filter Everything, WooCommerce Product Filters): When a shopper filters a 48-product category grid by size or color over AJAX, JavaScript-only lazy-loaders frequently leave newly inserted
<img data-src="...">cards blank because no scroll event re-initialized their observer. BecauseImageLazyOptimizer.phpemits native browser<img src="..." loading="lazy" decoding="async" width="..." height="...">markup without strippingsrc, AJAX-inserted product cards render immediately on every filter interaction! - Single-Product Variation Swatch Switching: Clicking a color swatch on
/product/merino-travel-hoodie/swaps the primary product gallerysrcandsrcsetattributes cleanly while keeping the initial main product image eager for fast mobileLCP. - RSS Feeds, REST API Responses & AMP / Print Views:
ImageLazyOptimizer.phpruns strictly on public HTML frontend documents—leaving/feed/XML entries,/wp-json/REST payloads, and admin previews untouched.
Frequently Asked Operational Questions
Will adding width and height attributes distort responsive images on mobile screens?
Does ImageDimensionResolver open image files on disk on every cached pageview?
Why does KadiCache use native browser loading="lazy" instead of a heavy jQuery lazyload library?
Does Image Lazyload work with responsive <picture> tags and srcset attributes?
How do I stop one specific above-the-fold badge or slider image from being lazy-loaded?
Creator of KadiCache’s Early PHP Drop-In, 7-Driver Object Cache Engine, Cloud Remove Unused CSS, and Zero-CLS Lazy Render pipeline.