094
LVL 04 — SENIOR-IN-TRAININGSESSION 094DAY 94

CORE WEB VITALS

🎫 PIXELCRAFT-080
Performance | 🟡 Medium | Priority: 🟠 High

Our Lighthouse score is 62. Competitors score 90+. Optimize for Core Web Vitals: LCP, CLS, INP. Hit 90+ on Performance.
CONCEPTS.UNLOCKED
📊
Core Web Vitals
The metrics Google uses to rank websites. Three numbers that measure real user experience: loading speed (LCP), visual stability (CLS), and interactivity (INP). They affect SEO ranking directly.
🖼️
LCP < 2.5s
Largest Contentful Paint: how fast main content loads. The biggest image or text block visible in the viewport. Preload it, compress it, serve from CDN. Users judge your site by how fast THIS appears.
📐
CLS < 0.1
Cumulative Layout Shift: how much the page jumps. Image loads → content shifts down. Font loads → text reflows. Fix: set explicit width/height on images, use font-display: swap.
👆
INP < 200ms
Interaction to Next Paint: how fast clicks respond. User taps a button → how long until the screen updates? Web Workers (session 92) and throttling (session 91) already improved this.
📦
Bundle Analysis
What's in your JS bundle? Is lodash fully imported when you use one function? Is a 500KB charting library loaded on every page? Analyze, tree-shake, lazy-load. Every KB matters on mobile.
✂️
Code Splitting
Load only what's needed for the current page. React.lazy() + Suspense: the editor code loads when you navigate to /editor, not on the homepage. Smaller initial bundle = faster load.
HANDS-ON.TASKS
01
Run Lighthouse — Baseline Score

Open DevTools → Lighthouse tab → Generate report. Note the score and every suggestion. Screenshot the "before" state. You need to measure where you started to prove improvement.

02
Fix LCP — Preload Critical Resources
<!-- Preload critical font --> <link rel="preload" href="/fonts/inter.woff2" as="font" type="font/woff2" crossorigin> <!-- Preload critical CSS --> <link rel="preload" href="/assets/main.css" as="style"> <!-- Font optimization --> @font-face { font-family: 'Inter'; src: url('/fonts/inter.woff2') format('woff2'); font-display: swap; /* Show fallback font immediately, swap when custom font loads. No invisible text. */ }
03
Fix CLS — Reserve Space for Images
// ❌ Before: image loads, shifts content <img src={thumbnail} alt={name} /> // ✅ After: reserve space before load <img src={thumbnail} alt={name} width={300} height={200} className="aspect-[3/2]" />
Setting width/height (or aspect-ratio in CSS) tells the browser how much space to reserve before the image downloads. Zero layout shift — the content never jumps.
04
Bundle Analysis & Tree Shaking
npx vite-bundle-analyzer // Common problems: // ❌ import _ from 'lodash' // (imports ALL of lodash: 72KB) // ✅ import debounce from // 'lodash/debounce' (4KB) // ❌ Full chart library on every page // ✅ Lazy-load only on analytics page // ❌ Duplicate dependencies // (two versions of the same lib) // ✅ npm dedupe
05
Code Splitting Per Route
import { Suspense, lazy } from 'react'; const Editor = lazy( () => import('./pages/Editor')); const Gallery = lazy( () => import('./pages/Gallery')); const Analytics = lazy( () => import('./pages/Analytics')); function App() { return ( <Suspense fallback={<Loading />}> <Routes> <Route path="/editor" element={<Editor />} /> <Route path="/gallery" element={<Gallery />} /> <Route path="/analytics" element={<Analytics />} /> </Routes> </Suspense> ); } // Only loads Editor code when // navigating to /editor. // Homepage bundle stays small.
06
Close the Ticket
git switch -c perf/PIXELCRAFT-080-core-web-vitals git add src/ index.html git commit -m "Optimize Core Web Vitals: LCP, CLS, code splitting (PIXELCRAFT-080)" git push origin perf/PIXELCRAFT-080-core-web-vitals # PR → Review → Merge → Close ticket ✅
CS.DEEP-DIVE

Web performance is user perception engineering.

The metrics (LCP, CLS, INP) are calibrated to match human perception thresholds. Performance isn't a nice-to-have — it directly impacts revenue.

// Human perception thresholds:

100ms  feels instant
300ms  feels sluggish
1s     breaks mental flow
10s    loses the user entirely

// Business impact (real data):
Amazon: every 100ms of latency
  costs 1% of sales

Google: 500ms slowdown reduced
  search traffic by 20%

Walmart: every 1s improvement
  increased conversions by 2%

// Performance = revenue.
// Performance = SEO ranking.
// Performance = user retention.
"Vitals Lab"
[A]Add real user monitoring (RUM): install web-vitals library, collect LCP/CLS/INP from actual users, send to your analytics. Lab data (Lighthouse) vs field data (real users) — both matter.
[B]Add a performance budget to CI: if bundle size exceeds 200KB gzipped, or Lighthouse score drops below 85, the build fails. Performance regressions are caught before merge.
[C]Research: what is the "cost of JavaScript"? Parse time, compile time, execution time — all are proportional to file size. On a mid-range phone, 1MB of JS can take 3+ seconds to parse. Write a brief analysis for PixelCraft.
REF.MATERIAL
ARTICLE
Google
Official guide to LCP, CLS, and INP: what they measure, target thresholds, and how to optimize each one.
VITALSOFFICIALESSENTIAL
VIDEO
Google Chrome Developers
Visual explanation of LCP, CLS, and INP with real-world examples. How to measure and fix each metric.
VITALSVISUAL
ARTICLE
Google
Official Lighthouse documentation: running audits, understanding scores, and automated performance testing in CI.
LIGHTHOUSEOFFICIAL
ARTICLE
Google
Route-based and component-based code splitting in React. Reduce initial bundle size and improve Time to Interactive.
REACTSPLITTING
VIDEO
Google Chrome
Performance budgets, Core Web Vitals, and practical optimization strategies. The Google-recommended approach to web performance.
PERFORMANCEESSENTIAL
// LEAVE EXCITED BECAUSE
Lighthouse score went from 62 to 94. Page loads in 1.2 seconds. Zero layout shifts. Clicks respond in under 100ms. This is the polish that separates professional from amateur.