Skip to content
Tutorials Center
My learning

Topics

Lesson 32 of 37 ยท Performance and Limits

Images and Web Vitals

Make sites fast: automatic image optimization and resizing on Vercel and Netlify, srcset and modern formats, lazy loading, and measuring LCP, INP and CLS with Speed Insights and Lighthouse.

Images are usually the heaviest part of a page. Both platforms can resize and convert images on the fly and cache the result on the CDN, so you upload one good original and visitors receive a small file matched to their screen. This lesson covers how that works and how to measure the outcome with Core Web Vitals.

The platforms and their image services cannot run here. Parameter names are from documentation and can change. The runnable code is a JavaScript stand-in for size math and metric classification, with invented numbers.

Image optimization services

  • Vercel Image Optimization is used through your framework's image component (next/image in Next.js, similar components elsewhere). Requests go to a path like /_next/image?url=...&w=640&q=75, and the platform returns a resized, compressed AVIF or WebP when the browser accepts it. Results are cached. Usage is metered on paid plans, and remotePatterns in config restricts which external image hosts may be optimized, so strangers cannot use your quota.
  • Netlify Image CDN transforms images through /.netlify/images?url=/photo.jpg&w=640&fm=webp. You allow remote sources in netlify.toml, and frameworks with Netlify adapters use it automatically.
  • Any other image service (Cloudinary, imgix, Cloudflare Images) works too: you just put its URL in your <img>.

For purely static sites you can also optimize at build time with a plugin or script, which costs nothing at run time.

What good image markup looks like

HTML
<img
  src="/img/hero-800.webp"
  srcset="/img/hero-400.webp 400w, /img/hero-800.webp 800w, /img/hero-1600.webp 1600w"
  sizes="(min-width: 900px) 800px, 100vw"
  width="800" height="450"
  alt="A mountain village at dawn"
  loading="lazy" decoding="async">
  • srcset + sizes let the browser pick the smallest adequate file.
  • width and height reserve space, which prevents layout shift.
  • loading="lazy" delays offscreen images. Do not lazy-load the main hero image: it should load at high priority (fetchpriority="high").
  • Prefer AVIF or WebP; keep JPEG or PNG as fallbacks only where needed. SVG for icons and logos.

Faster images

Right size Serve what the screen needs.
Modern format AVIF or WebP.
Reserve space Set width and height.
Lazy load Everything below the fold.

Hero image: eager and high priority.

1 / 2

Estimating what a visitor downloads

The stand-in picks a srcset candidate the way a browser would (smallest candidate at least as wide as needed, given display width and pixel ratio), then estimates bytes using an invented bytes-per-pixel figure.

JS srcset chooser stand-in

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Core Web Vitals

Google measures real-user experience with three vitals; the "good" thresholds, at the 75th percentile of visits, are:

Metric Measures Good Poor
LCP (Largest Contentful Paint) when the main content appears 2.5 s or less over 4 s
INP (Interaction to Next Paint) responsiveness to clicks and taps 200 ms or less over 500 ms
CLS (Cumulative Layout Shift) unexpected movement of content 0.1 or less over 0.25

Between good and poor is "needs improvement". Typical fixes: LCP improves with a smaller, preloaded hero image and faster server responses (caching, see Caching and the CDN); INP improves by shipping less JavaScript and breaking up long tasks; CLS improves with image dimensions and reserved space for ads and embeds.

JS Web Vitals classifier stand-in

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Measuring on the platforms

  • Lab tests: Lighthouse (built into Chrome DevTools) on a preview deployment gives repeatable scores and tips. Netlify has a Lighthouse plugin and Vercel can run checks in CI. Lab numbers vary with machine and network, so treat them as diagnostics.
  • Field data: Vercel Speed Insights and Web Analytics collect real visitor metrics through a small script; Netlify's analytics and third-party tools such as the Chrome User Experience Report (CrUX) do the same. Field data decides what users really feel and what Google sees.
  • Use preview deployments to compare before and after for each change.

Other quick wins

  • Serve fonts from your own domain, preload the primary one and use font-display: swap.
  • Send less JavaScript: code-split routes, drop unused libraries, defer third-party scripts.
  • Use Link: <url>; rel=preload headers for critical resources (Response Headers and Security).
  • Choose a function region close to your data and users.
  • Compress text (Brotli) automatically on both platforms.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why set width and height on an img?

    The browser can lay out the page before the image arrives, so nothing jumps.
  2. 2. Which image should NOT use loading=lazy?

    Lazy loading delays the image, hurting LCP. Load it eagerly with high priority.
  3. 3. What is a good LCP at the 75th percentile?

    Google's threshold for good LCP is 2.5 s or less.
  4. 4. Why use field data in addition to Lighthouse?

    Lab scores are repeatable diagnostics; real-user metrics decide the actual experience.

Summary

  • Image optimization services resize and convert images on demand and cache them on the CDN.
  • Use srcset, sizes, explicit dimensions, modern formats and lazy loading (except the hero).
  • Core Web Vitals: LCP, INP and CLS, each with published thresholds.
  • Combine Lighthouse (lab) with Speed Insights or CrUX (field).
  • Restrict remote image sources so strangers cannot use your quota.

Next: Limits, Quotas and Costs