Loading...
Loading...
LCP, INP, CLS — and every optimization technique SDE-2 interviews expect.
Core Web Vitals (LCP, INP, CLS), Critical Rendering Path optimization, image/JS/CSS/network tuning, and the tools SDE-2 frontend engineers use to measure and budget performance.
The three Core Web Vitals — LCP, INP, and CLS — plus Critical Rendering Path optimization, image/JS/CSS/network tuning, and performance measurement tools for production-grade frontend engineering.
Web performance is not one trick — it is a stack of measurable optimizations aligned to Core Web Vitals. LCP measures loading, INP measures responsiveness, and CLS measures visual stability.
This module covers the fix techniques, code patterns, and tooling interviewers expect at SDE-2 level: from preloading LCP images to breaking up long tasks, from Brotli compression to Lighthouse performance budgets.
You will learn how to read a Lighthouse report, set performance budgets, prioritize fixes by Web Vitals impact, and explain the difference between lab data and real-user monitoring in production.
Topics include image lazy-loading and responsive srcset, code splitting and tree shaking, font loading strategies, CDN caching, and breaking long tasks that hurt INP on low-end devices.
Google uses Core Web Vitals as ranking signals. Slow LCP loses users before they read content. High INP makes apps feel broken. Poor CLS erodes trust. SDE-2 engineers are expected to diagnose, fix, and prevent all three — and explain the difference between optimizing for lab scores vs real-user monitoring data.
The 3 metrics Google uses to measure real-world user experience (SDE-2 must-know).
Core Web Vitals are field metrics that reflect how real users experience your site. They replaced vague “fast enough” goals with measurable thresholds you can optimize in code, infrastructure, and CI.
Interactive · Core Web Vitals simulator
Adjust inputs to see estimated LCP, INP, and CLS — not lab-accurate, but shows which levers matter most.
LCP
1780ms
good
INP
423ms
needs
CLS
0.23
needs
Largest Contentful Paint
Loading — when the biggest visible element appears
Interaction to Next Paint
Responsiveness — delay after every click, tap, or key
Cumulative Layout Shift
Visual stability — unexpected layout movement
INP replaced FID (March 2024)
Loading performance: time until the largest visible element is painted.
Good
< 2.5s
Needs improvement
2.5s – 4.0s
Poor
> 4.0s
What hurts LCP
Fix techniques
<link rel="preconnect" href="https://cdn.example.com"> <link rel="preload" as="image" href="/hero.avif" fetchpriority="high">
Responsiveness: how quickly the page reacts to user input.
Good
< 200ms
Needs improvement
200ms – 500ms
Poor
> 500ms
What hurts INP
Fix techniques
Visual stability: how much content jumps around unexpectedly.
Good
< 0.1
Needs improvement
0.1 – 0.25
Poor
> 0.25
What hurts CLS
Fix techniques
<img src="photo.jpg" width="800" height="600" alt="..."> /* or */ .hero { aspect-ratio: 16 / 9; }
Minimize the steps from HTML/CSS/JS to first paint.
CRP is the sequence the browser follows to render the first frame. Optimizing CRP directly improves LCP and first paint — every render-blocking resource adds delay.
| Strategy | How | Impact |
|---|---|---|
| Inline critical CSS | Above-fold styles in <style> in <head> | Reduces blocking |
| Defer non-critical JS | defer or async attribute | Prevents parse blocking |
| Preload critical assets | <link rel="preload"> | Faster discovery |
| Preconnect to origins | <link rel="preconnect"> | Early DNS/TLS |
| Prefetch future resources | <link rel="prefetch"> | Speeds next navigation |
| Minimize payload size | Minify + Brotli/GZIP | Faster download |
Images are often the LCP element — optimize them first.
| Technique | Example | Benefit |
|---|---|---|
| Modern formats | <img src="image.avif"> | 50–70% smaller than JPEG |
| Responsive images | srcset + sizes attributes | Loads appropriate size |
| Lazy loading | loading="lazy" | Skips off-screen images |
| Explicit dimensions | width="800" height="600" | Prevents CLS |
| CSS aspect-ratio | aspect-ratio: 800/600 | CLS without attributes |
| Image CDN | Cloudinary, Imgix | Auto-format on request |
Avoid animated GIFs
Bundle size, code splitting, and React render optimization.
// ❌ BAD: entire library import { everything } from 'big-library'; // ✅ GOOD: specific import import { specificFunc } from 'big-library/specific'; // ✅ BETTER: dynamic import const mod = await import('big-library/specific');
| Technique | Description | When |
|---|---|---|
| Code splitting | Split bundle into chunks | Large apps, routes |
| Lazy loading | React.lazy(), dynamic import() | Non-critical UI |
| Tree shaking | Remove unused exports | All bundler projects |
| Minification | Terser, esbuild | All production builds |
| Compression | Brotli (preferred), GZIP | All network payloads |
| Web Workers | Offload heavy compute | Parsing, hashing, data |
React performance
// ❌ Re-renders every parent update const Child = ({ value }) => <div>{value}</div>; // ✅ Memoize stable children const Child = memo(({ value }) => <div>{value}</div>); // ✅ Memoize expensive derived data const filtered = useMemo(() => data.filter(fn), [data]);
Smaller stylesheets, faster style computation, skip off-screen work.
| Technique | Example | Benefit |
|---|---|---|
| Remove unused CSS | PurgeCSS | Smaller bundle |
| Minify CSS | CSSNano | Smaller file |
| Inline critical CSS | <style> in <head> | Faster first paint |
| Simple selectors | .card-title vs .a .b .c span | Faster style calc |
| content-visibility | content-visibility: auto | Skip off-screen layout |
| contain | contain: layout style paint | Isolate reflow scope |
HTTP/2, CDN strategy, and cache headers.
// ❌ Single origin <img src="https://origin.com/image.jpg"> // ✅ CDN + long cache <img src="https://cdn.example.com/image.jpg"> // Cache-Control: public, max-age=31536000
| Header | Value | Use case |
|---|---|---|
| Cache-Control | public, max-age=31536000 | Static assets (JS, CSS, images) |
| Cache-Control | no-cache | HTML pages (revalidate each visit) |
| Cache-Control | private, max-age=0 | Authenticated content |
| ETag | Auto-generated | Version-based conditional cache |
Measure in lab and field; enforce limits in CI.
| Tool | Type | Measures |
|---|---|---|
| Lighthouse | Lab | CWV scores, best practices |
| PageSpeed Insights | Lab + Field | Real-user CWV data |
| Chrome DevTools | Lab | Timeline, network, memory |
| web-vitals (npm) | Field | Programmatic CWV reporting |
| RUM (Sentry, DataDog, GA4) | Field | Production user metrics |
| WebPageTest | Lab | Deep waterfall analysis |
Performance budget example
// Lighthouse CI or custom script { "maxTotalSize": "1MB", "maxJSBundle": "200KB", "maxImages": "500KB", "maxLCP": "2.5s", "maxINP": "200ms" }
Lab vs field
Core Web Vitals and performance optimization.