Lab 04: Performance Architecture

Time: 60 minutes | Level: Architect | Docker: node:20-alpine

Overview

Master Core Web Vitals optimization: LCP via preload and resource hints, CLS elimination via explicit dimensions and font-display, INP via deferred non-critical JS, content-visibility:auto for long pages, critical CSS extraction, and HTTP/2 push vs preload tradeoffs.


Step 1: Core Web Vitals Architecture Overview

CWV Targets (2024 thresholds):
  LCP (Largest Contentful Paint) — < 2.5s (Good), < 4s (Needs Improvement)
  INP (Interaction to Next Paint) — < 200ms (replaces FID)
  CLS (Cumulative Layout Shift) — < 0.1

CSS Contribution:
  LCP: render-blocking CSS, missing preload, no critical CSS inline
  CLS: images without dimensions, late-loaded fonts, dynamic content injection
  INP: long tasks from layout thrashing, heavy style recalculations

Step 2: LCP Optimization

💡 fetchpriority="high" on the LCP image signals to the browser's preload scanner to fetch it before layout is complete. This alone can improve LCP by 200–400ms.


Step 3: CLS Prevention


Step 4: INP Optimization


Step 5: content-visibility for Long Pages

💡 content-visibility: auto can reduce initial rendering time by 40–60% on long pages. Without contain-intrinsic-size, the scrollbar jumps as elements render in.


Step 6: Critical CSS Extraction


Step 7: HTTP/2 Push vs Preload


Step 8: Capstone — Critical CSS Extractor

📸 Verified Output:


Summary

CWV Metric
CSS Technique
Impact

LCP

fetchpriority="high", preload

-200–400ms

LCP

Inline critical CSS

Eliminate 1 RTT

LCP

font-display: optional

No render block

CLS

aspect-ratio on images

Zero shift

CLS

Font metrics override

Match fallback

CLS

contain-intrinsic-size

Stable scroll

INP

Single CSS var mutation

One reflow

INP

contain: layout

Scope reflow

All

content-visibility: auto

40-60% render time

Last updated