Skip to main content

Why Performance Matters

Performance is a critical aspect of frontend development that directly impacts user experience, engagement, and conversion rates. Studies have shown that:
  • 53% of mobile users abandon sites that take longer than 3 seconds to load
  • Every 100ms of latency costs Amazon 1% in sales
  • Google uses page speed as a ranking factor for both desktop and mobile searches
Performance optimization is not just about making your site fast—it’s about creating a smooth, responsive experience that keeps users engaged and satisfied.

Performance Metrics

Before optimizing, it’s important to understand what to measure. Here are key performance metrics to track:

First Contentful Paint (FCP)

Time until the browser renders the first bit of content from the DOM.Good target: Under 1.8 seconds

Largest Contentful Paint (LCP)

Time until the largest text or image element is rendered.Good target: Under 2.5 seconds

First Input Delay (FID)

Time from when a user first interacts with your site to when the browser responds.Good target: Under 100 milliseconds

Cumulative Layout Shift (CLS)

Measures visual stability and unexpected layout shifts.Good target: Under 0.1

Time to Interactive (TTI)

Time until the page is fully interactive.Good target: Under 3.8 seconds

Total Blocking Time (TBT)

Sum of all time periods between FCP and TTI when the main thread was blocked.Good target: Under 200 milliseconds

Measuring Performance

Tools for Performance Measurement

1

Lighthouse

Chrome’s built-in auditing tool that provides performance scores and suggestions.Access it through Chrome DevTools > Lighthouse tab or run it from the command line:
2

WebPageTest

Provides detailed performance analysis from multiple locations and browsers.Visit WebPageTest.org to run tests.
3

Chrome DevTools Performance Panel

Offers detailed runtime performance analysis including CPU usage, rendering, and network activity.
  1. Open Chrome DevTools (F12)
  2. Go to the Performance tab
  3. Click Record and interact with your site
  4. Stop recording and analyze the results
4

Core Web Vitals Report

Google’s report on real-user performance metrics.Access it through Google Search Console.

Real User Monitoring (RUM)

While lab testing is valuable, measuring performance with real users provides the most accurate data:

Optimizing Asset Delivery

Image Optimization

Images often account for the largest portion of page weight. Here’s how to optimize them:
Use tools like ImageOptim, TinyPNG, or Sharp to compress images without significant quality loss.
Always serve images at the appropriate size for their display dimensions.
WebP, AVIF, and JPEG XL offer better compression than older formats like JPEG and PNG.
Only load images when they’re about to enter the viewport.
For broader browser support, use a library like lazysizes:
Serve different image sizes based on the device’s screen size.

JavaScript Optimization

Split your JavaScript into smaller chunks that load on demand.
With webpack:
Reduce file size by removing unnecessary characters and compressing the code.
Enable Gzip or Brotli compression on your server:
Prevent JavaScript from blocking the page render.
Remove unused code from your bundles.
Use ES modules to enable tree shaking:

CSS Optimization

Inline critical styles in the <head> and load the rest asynchronously.
Tools like Critical or CriticalCSS can automate this process.
Remove unused styles to reduce file size.
Load non-critical CSS asynchronously.
Use efficient selectors to improve rendering performance.

Fonts Optimization

System fonts load instantly because they’re already installed.
Use font-display to control how fonts are displayed while loading.
Preload important fonts:
Only include the characters you need.
Use tools like glyphhanger to create custom subsets.
Each font weight and style is a separate download.

Rendering Performance

Optimizing the Critical Rendering Path

1

Minimize render-blocking resources

Move non-critical CSS and JavaScript out of the critical rendering path.
2

Optimize DOM size

Keep the DOM tree small and shallow.
3

Avoid layout thrashing

Batch DOM reads and writes to prevent forced reflows.
4

Use efficient CSS animations

Prefer properties that only affect compositing.

Preventing Layout Shifts

Layout shifts create a poor user experience and negatively impact your CLS score.

Network Optimization

Caching Strategies

Configure proper cache headers to reduce server requests.
Implement offline caching with service workers.
Use browser memory cache for frequently accessed data.

Resource Hints

Use resource hints to inform the browser about resources it should load or connect to:

Framework-Specific Optimizations

React

Vue.js

Angular

Performance Budgets

Set performance budgets to maintain performance standards as your project evolves:
In your CI/CD pipeline, you can use tools like Lighthouse CI to enforce performance budgets:

Checklist for Performance Optimization

Use this checklist to ensure you’ve covered the most important performance optimizations:
1

Measure current performance

  • Run Lighthouse audits
  • Set up real user monitoring
  • Identify the biggest performance bottlenecks
2

Optimize asset delivery

  • Compress and optimize images
  • Minify and compress JavaScript and CSS
  • Implement code splitting
  • Use tree shaking
  • Optimize fonts
3

Improve rendering performance

  • Minimize render-blocking resources
  • Optimize the critical rendering path
  • Prevent layout shifts
  • Use efficient animations
4

Implement caching strategies

  • Configure HTTP caching
  • Implement service workers
  • Use resource hints
5

Apply framework-specific optimizations

  • Use memoization techniques
  • Implement lazy loading
  • Optimize rendering cycles
6

Set up performance monitoring

  • Establish performance budgets
  • Integrate performance testing in CI/CD
  • Monitor real user metrics

Next Steps

Now that you understand frontend performance optimization, you can:
  • Learn about Accessibility to make your sites usable by everyone
  • Explore Security best practices to protect your applications
  • Study Testing strategies to ensure your optimizations don’t break functionality