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.- Basic usage
- Custom comparison
- With callbacks
data or onSelect changes.useMemo and useCallback
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
- Fixed size list
- Variable size list
- Grid
Image optimization
Images are often the largest assets on web pages. Proper optimization is crucial for performance.Image formats
WebP - Modern format
WebP - Modern format
Superior compression with excellent quality. Supported in all modern browsers.Benefits: 25-35% smaller than JPEG, supports transparency and animation.
AVIF - Next-gen format
AVIF - Next-gen format
Even better compression than WebP, but limited browser support.Benefits: Up to 50% smaller than JPEG with better quality.
SVG - Vector graphics
SVG - Vector graphics
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
- Critical fonts
- Next.js 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
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.Code splitting strategies
Split your code into smaller chunks to reduce initial load time.Route-based splitting
- React Router
- Next.js
Component-based splitting
Vendor 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