A web page loads slowly. How do you diagnose and improve it?
Answer
- Measure first: Lighthouse, Chrome DevTools (Performance, Network), real-user Core Web Vitals.
- Network: compression (Brotli), CDN, HTTP caching, fewer/smaller requests, preconnect.
- Assets: optimize images (WebP/AVIF, correct sizes, lazy loading), code splitting, tree shaking, defer non-critical JS.
- Rendering: avoid huge DOMs and layout thrashing; reserve space for images to prevent CLS; virtualize long lists.
- Backend: slow time-to-first-byte → profile the API and database, add caching.
- Set performance budgets and monitor them in CI.
Practice this question in Repaso