Skip to main content

Beginner-Friendly Topic

Take your time - it's perfectly normal to re-read this topic 2-3 times. Try the interactive code editor below to run code yourself. Use the Q&A section to check your understanding before moving on.You've got this!

Lesson 5 of 10

Image & Asset Optimization

Images are typically the largest assets on a page and the primary cause of poor Largest Contentful Paint (LCP) scores. Proper lazy loading, next-gen formats, and responsive images are foundational performance techniques that require no JavaScript.

20 minBy Priygop Editorial TeamUpdated 2026Peer Reviewed & Verified

Lazy Loading, Modern Formats & Responsive Images

Lazy Loading, Modern Formats & Responsive Images
// 1. Native lazy loading - loads image only when near the viewport
<img
  src="photo.webp"
  loading="lazy"           // native browser lazy loading
  decoding="async"         // decode off main thread
  alt="Description"
/>

// 2. Priority for above-the-fold images - don't lazy load LCP image
<img
  src="hero.webp"
  loading="eager"          // load immediately (default for above fold)
  fetchpriority="high"     // hint browser to fetch this first
  alt="Hero image"
/>

// 3. picture element - serve WebP with JPEG fallback
<picture>
  <source srcSet="image.avif" type="image/avif" />
  <source srcSet="image.webp" type="image/webp" />
  <img src="image.jpg" alt="Product" loading="lazy" />
</picture>

// 4. Responsive images - serve correctly sized image for device
<img
  srcSet="
    photo-480w.webp  480w,
    photo-800w.webp  800w,
    photo-1200w.webp 1200w
  "
  sizes="(max-width: 480px) 480px, (max-width: 800px) 800px, 1200px"
  src="photo-1200w.webp"
  alt="Responsive photo"
  loading="lazy"
/>

// 5. Next.js Image component - handles everything automatically
import Image from 'next/image';
<Image
  src="/hero.jpg"
  width={1200}
  height={630}
  alt="Hero"
  priority          // add to above-fold images only
  placeholder="blur" // show blurred placeholder while loading
  blurDataURL="data:image/jpeg;base64,..." // tiny base64 representation
/>

// 6. Cumulative Layout Shift (CLS) prevention
// Always specify width and height (or aspect-ratio) to reserve space
// Without dimensions, images cause layout shifts when they load
img { aspect-ratio: 16/9; width: 100%; object-fit: cover; }

Tip

Tip

Practice Image Asset Optimization in small, isolated examples before integrating into larger projects. Breaking concepts into small experiments builds genuine understanding faster than reading alone.

Diagram
Loading diagram…

Visual architecture and flow for Image & Asset Optimization

Practice Task

Note

Practice Task - (1) Write a working example of Image Asset Optimization from scratch without looking at notes. (2) Modify it to handle an edge case (empty input, null value, or error state). (3) Share your solution in the Priygop community for feedback.

Quick Quiz

Common Mistake

Warning

A common mistake with Image Asset Optimization is skipping edge case testing - empty inputs, null values, and unexpected data types. Always validate boundary conditions to write robust, production-ready react code.

Hands-on Practice Tools for this Course

Test what you learn using these free in-browser developer utilities (no signup required).

All 40+ Tools

Topics in This Module

0/10 done