Learn the Good Patterns
Real-world engineering guide on how top e-commerce websites achieve sub-1.0s LCP, zero layout shifts, impenetrable checkout security, and effortless scale.
Core Web Vitals: Sub-1.0s LCP, CLS 0.00 & Image Compression
Mastering Google Core Web Vitals: Largest Contentful Paint (LCP < 1.2s), Cumulative Layout Shift (CLS = 0.00), and modern AVIF/WebP image formatting with explicit dimensions.
Next-Gen WebP/AVIF, Explicit Dimensions & High-Priority LCP
Product photography is the largest bandwidth consumer in e-commerce. A top-tier storefront converts images to WebP/AVIF (reducing sizes by 80%), provides explicit width and height attributes to lock layout boxes and achieve CLS 0.00, and attaches fetchpriority="high" to the primary hero product image to ensure an LCP under 1.0 second.
<!-- Optimized Product Hero Image (Zero CLS & Sub-1s LCP) -->
<picture>
<source srcset="/images/shoes/aura-pro-800.avif" type="image/avif" />
<source srcset="/images/shoes/aura-pro-800.webp" type="image/webp" />
<img
src="/images/shoes/aura-pro-800.jpg"
alt="Aura Velocity Pro carbon running shoe in obsidian black"
width="800"
height="600"
fetchpriority="high"
decoding="async"
className="aspect-[4/3] w-full rounded-2xl object-cover"
/>
</picture>
<!-- Next.js equivalent: -->
// <Image
// src="/images/shoes/aura-pro.webp"
// alt="Aura Velocity Pro"
// width={800}
// height={600}
// priority={true} // Injects <link rel="preload"> in <head> for instant LCP
// />Key Engineering & Business Benefits:
- Achieves a flawless 0.00 Cumulative Layout Shift (CLS) score on Google Core Web Vitals.
- Slashes mobile data consumption by up to 85% for shoppers on metered cell networks.
- Boosts Google search organic ranking by qualifying for mobile search speed badges.
The Horror Site: 12MB Raw Uncompressed PNG & Jumping Text
The bad site loaded a raw 12MB camera photo (shoe-photo.png) with no width or height dimensions. When the image finally finished downloading after 8 seconds, it pushed the product text down by 600 pixels, creating a disastrous CLS of 0.82 and driving frustrated shoppers away.
<!-- 12 Megabytes raw camera file with no layout dimensions: -->
<img src="http://worst-deals-ever.fake/shoe-huge-raw-camera.png" />
<!-- Page jumps and stutters as image loads! CLS: 0.82 -->How to Implement / Fix in 3 Practical Steps
Compress all product imagery into WebP or AVIF formats under 90KB per image.
Always specify explicit width and height attributes or CSS aspect-ratio on all images.
Add fetchpriority="high" or priority={true} to the main product photo to accelerate LCP.
DevTools -> Network -> Filter by "Img" -> Inspect Size and Time columns. Run Lighthouse to verify CLS is 0.00 and LCP is below 1.2s.
Finished reading this lesson?
Mark it as mastered below, or click Next Lesson to auto-complete.