Unit 6.1 · Tutorial 1

Web Performance Fundamentals

Chapter 17 · Advanced Topics
~2.5 hours Intermediate Core Web Vitals · Lighthouse · Bundling

Overview

Speed is a feature. This tutorial covers the fundamentals of web performance: measuring and optimising your application using Core Web Vitals, Lighthouse audits, bundle optimisation, code splitting, and lazy loading. You'll learn how to make your application faster and more responsive.

Why this matters: Performance directly impacts user experience, conversion rates, and SEO. A 100ms delay can reduce conversion by 7%. Optimising performance is essential for any production application.

1. Performance Metrics & Core Web Vitals

Core Web Vitals are Google's standard metrics for user experience:

  • LCP (Largest Contentful Paint): Loading performance. Time to render the largest content element. Target: < 2.5s.
  • FID (First Input Delay): Interactivity. Time from user interaction to browser response. Target: < 100ms.
  • CLS (Cumulative Layout Shift): Visual stability. Unexpected layout shifts. Target: < 0.1.
  • FCP (First Contentful Paint): First content appears. Target: < 1.8s.
  • TTI (Time to Interactive): Page becomes fully interactive. Target: < 5s.
// Measuring Web Vitals in JavaScript import { onCLS, onFID, onLCP, onFCP, onTTFB } from 'web-vitals'; function sendToAnalytics({ name, value, id }) { console.log(`Web Vitals: ${name} = ${value}`); } onCLS(sendToAnalytics); onFID(sendToAnalytics); onLCP(sendToAnalytics); onFCP(sendToAnalytics); onTTFB(sendToAnalytics);

2. Lighthouse Audits

Lighthouse is an open‑source tool for auditing performance, accessibility, SEO, and more. Run it in Chrome DevTools or via CLI.

# CLI usage npx lighthouse https://example.com --output html --output-path ./report.html # With custom settings npx lighthouse https://example.com --preset desktop --only-categories=performance

Lighthouse performance categories:

  • Performance: LCP, FID, CLS, FCP, TTI, TBT (Total Blocking Time).
  • Accessibility: Semantic HTML, ARIA, contrast.
  • Best Practices: Security, modern standards.
  • SEO: Meta tags, robot rules.
  • PWA: Progressive Web App capabilities.
Tip: Run Lighthouse on every PR to track performance regressions using automated CI integration.

3. Bundling & Code Splitting

Bundlers (Webpack, Vite, Rollup) combine modules into optimised bundles.

Code splitting strategies

  • Route‑based: Each route loads its own chunk.
  • Component‑based: Large components (modals, charts) load on demand.
  • Vendor splitting: Third‑party libraries in separate bundles.
// React route-based code splitting import { lazy, Suspense } from 'react'; import { BrowserRouter, Routes, Route } from 'react-router-dom'; const Home = lazy(() => import('./pages/Home')); const Dashboard = lazy(() => import('./pages/Dashboard')); const Settings = lazy(() => import('./pages/Settings')); function App() { return ( Loading...
}> } /> } /> } /> ); }