Skip to main content

Overview

Once you’ve identified performance bottlenecks using profiling tools, the next step is applying targeted optimization techniques. This guide covers the most impactful optimization strategies for modern web applications.
Optimization should be data-driven. Always measure before and after to verify improvements and avoid premature optimization.

Component memoization strategies

Memoization prevents unnecessary re-renders by caching component outputs and computation results.

React.memo

Wraps functional components to prevent re-renders when props haven’t changed.
Component only re-renders when data or onSelect changes.

useMemo and useCallback

Don’t memoize everything. Memoization has overhead. Only memoize expensive computations or when preventing re-renders of child components.

Virtualized lists and windowing

Virtualization renders only visible items in large lists, dramatically improving performance.

Why virtualization matters

Without virtualization

Rendering 10,000 items creates 10,000 DOM nodes, causing:
  • Slow initial render
  • High memory usage
  • Sluggish scrolling
  • Browser freezing

With virtualization

Only renders ~20 visible items at a time:
  • Fast initial render
  • Low memory footprint
  • Smooth 60fps scrolling
  • Responsive UI

Using react-window

Best for lists with uniform item heights.
Use react-window for most cases. For more advanced features like dynamic loading and sticky headers, consider react-virtualized.

Image optimization

Images are often the largest assets on web pages. Proper optimization is crucial for performance.

Image formats

Superior compression with excellent quality. Supported in all modern browsers.
Benefits: 25-35% smaller than JPEG, supports transparency and animation.
Even better compression than WebP, but limited browser support.
Benefits: Up to 50% smaller than JPEG with better quality.
Perfect for icons, logos, and illustrations that need to scale.
Benefits: Infinitely scalable, small file size, CSS/JS controllable.

Lazy loading

Responsive images

Font optimization

Web fonts can significantly impact page load performance if not optimized properly.

Subsetting

Reduce font file size by including only needed characters.

Preloading fonts

Font display strategies

font-display: swap

Show fallback font immediately, swap when custom font loads.Best for: Most use cases. Avoids invisible text.

font-display: optional

Use custom font only if already cached, otherwise use fallback.Best for: Performance-critical pages where font is not essential.

font-display: fallback

Brief block period, then show fallback, swap if font loads quickly.Best for: Balance between swap and optional.

font-display: block

Wait for font to load before showing text (up to 3s).Best for: When font is critical to design (use sparingly).

Bundle analysis and tree shaking

Analyze and optimize your JavaScript bundles to reduce load times.

Analyzing bundles

1

Install analyzer

2

Configure webpack

3

Run build

Open bundle-report.html to visualize your bundle composition.
4

Identify issues

Look for:
  • Large dependencies that can be replaced
  • Duplicate modules
  • Unused code
  • Opportunity for code splitting

Tree shaking

Eliminate unused code from bundles.
Tree shaking only works with ES modules (import/export). CommonJS modules (require/module.exports) cannot be tree-shaken.

Code splitting strategies

Split your code into smaller chunks to reduce initial load time.

Route-based splitting

Component-based splitting

Vendor splitting

Aim for chunk sizes between 20-200KB. Too many small chunks increase HTTP overhead, while large chunks defeat the purpose of splitting.

Performance optimization checklist

1

Measure baseline

  • Run Lighthouse audit
  • Profile with Chrome DevTools
  • Record Core Web Vitals
2

Optimize rendering

  • Memoize expensive components
  • Virtualize long lists
  • Avoid layout thrashing
3

Optimize assets

  • Convert images to WebP/AVIF
  • Implement lazy loading
  • Subset and preload fonts
4

Optimize bundles

  • Analyze bundle composition
  • Enable tree shaking
  • Implement code splitting
5

Verify improvements

  • Re-run Lighthouse
  • Compare metrics
  • Monitor real user metrics

Next steps

Profiling tools

Learn to identify performance bottlenecks using Chrome DevTools and React Profiler

Critical rendering path

Optimize initial page load by eliminating render-blocking resources