Frontend School
DashboardProblemsLearnPracticeMock InterviewReportsStatsBuy Credits
DashboardProblemsLearnPracticeMock Interview
Frontend System Design Fundamentals
  1. 1.Introduction to Frontend System Design
  2. 2.Core Frontend Architecture Concepts
  3. 3.Client-Server Interaction Fundamentals
  4. 4.Basic Performance & Accessibility Considerations
  5. 5.State Management Basics & Data Flow
  6. 6.Advanced State Management & Global Stores
  7. 7.Component Libraries & Design Systems
  8. 8.Frontend Build Tools & Development Workflows
  9. 9.Advanced Performance Optimization Techniques
  10. 10.Data Fetching Strategies & Caching
  11. 11.Frontend Security Essentials
  12. 12.Micro-Frontend Architectures
  13. 13.Real-time Communication & WebSockets
  14. 14.Observability, Monitoring, & Logging
  15. 15.Offline-First & Progressive Web Apps (PWAs)
Frontend System Design Fundamentals
09

Frontend System Design · Lesson 9 of 15 · 5 min

Advanced Performance Optimization Techniques

This is how you prove you can diagnose and fix a slow frontend, moving beyond the basics of build tools.

In an interview, you need to show you can make an application faster. This means going beyond what the build tool does automatically. You need to articulate a strategy, identify bottlenecks, and know the trade-offs for each optimization. This lesson covers the techniques that separate senior candidates from junior ones.

Shrink the Initial Payload

Your first goal is to send less code. The less JavaScript the browser has to download, parse, and execute, the faster your app becomes interactive.

Code splitting is your main tool for this. Instead of one giant app.js bundle, you create smaller "chunks" that are loaded on demand. The most common strategy is route-based splitting: when a user navigates to /settings, you only then load the JavaScript for the settings page.

Tree shaking is a related, but distinct, process. It's dead-code elimination that happens at build time. It removes unused exports from your final bundles. You rely on your build tool for this, but you enable it by writing modular code using import/export syntax.

The interview question: "A user opens our app and sees a blank screen for three seconds. What do you investigate?"

Your first step is to measure using tools like Lighthouse or WebPageTest to confirm the bottleneck. If the main JavaScript bundle is multiple megabytes, your answer is code splitting. Explain that you'd use a bundle analyzer to see what's in the main chunk and then implement dynamic import() for routes or large, non-critical components.

This is how you implement component-based code splitting in React. The HeavyComponent and its dependencies won't be in the initial bundle. They will be fetched only after the user clicks the button.

import React, { useState, Suspense, lazy } from 'react';

// Dynamically import the HeavyComponent. This creates a separate chunk.
const HeavyComponent = lazy(() => import('./HeavyComponent'));

function App() {
  const [show, setShow] = useState(false);

  return (
    <div>
      <h1>My App</h1>
      <button onClick={() => setShow(true)}>
        Load Heavy Feature
      </button>

      {/* Suspense provides a fallback while the lazy component is loading */}
      {show && (
        <Suspense fallback={<div>Loading...</div>}>
          <HeavyComponent />
        </Suspense>
      )}
    </div>
  );
}

// In another file: HeavyComponent.tsx
const HeavyComponent = () => {
  return (
    <div>
      <h2>This is a heavy component.</h2>
      <p>It was loaded on demand.</p>
    </div>
  );
};

export default HeavyComponent;

Unblock the Main Thread

A fast initial load is useless if the UI freezes afterward. This "jank" happens when a long-running task blocks the main thread, preventing the browser from responding to user input or painting updates. You have two primary tools to prevent this.

Web Workers run scripts in a background thread. This is for CPU-intensive work: complex calculations, data processing, or image manipulation. The main thread sends a message to the worker, stays responsive, and listens for the result.

Virtualization (or "windowing") is for rendering long lists. Instead of rendering 10,000 DOM nodes for a list, you only render the ~20 items currently visible in the viewport (plus a small buffer). As the user scrolls, you unmount nodes that leave the viewport and mount new ones that enter. This keeps scrolling smooth and memory usage low.

The trap: Don't reach for these tools prematurely. Virtualization adds complexity. If your list has 100 items, you don't need it. Web Workers require careful message passing. Profile your app first. If a specific function is causing a Long Animation Frame, and it's pure computation, then it's a candidate for a Web Worker.

Accelerate the Critical Path

The critical rendering path is the sequence of steps the browser takes to render the initial view. You can influence this path with server-side rendering and resource hints.

Server-Side Rendering (SSR) and Static Site Generation (SSG) both deliver pre-rendered HTML to the browser. This dramatically improves First Contentful Paint (FCP) because the user sees content before any JavaScript runs.

  • SSG: HTML is generated at build time. Fastest possible delivery. Best for content that doesn't change often, like a blog or documentation.
  • SSR: HTML is generated on the server for each request. Good for dynamic, user-specific content. The trade-off is higher server load and cost.

Resource Hints are <link> tags in your HTML that tell the browser what you'll need soon.

  • rel="preconnect": Tells the browser to perform the DNS/TCP/TLS handshake with a domain before a request is made. Use it for critical third-party origins, like an API or font provider.
  • rel="preload": Tells the browser to fetch a resource with high priority for the current page. Use it for assets you know are needed immediately for the initial render, like a font file used by your H1 or a critical CSS file.

The trap: Over-using preload is worse than not using it. Preloading a non-critical asset can delay more important resources. Only preload assets on the critical path. Always use the as attribute (as="font", as="style") so the browser can prioritize correctly.

Optimize Asset Delivery

Beyond JavaScript, your largest assets are often images. Serving a 2MB hero image designed for a 4K desktop to a mobile user on a 3G network is a common performance killer.

Use responsive images with the <img srcset> and sizes attributes. This lets you provide a list of image sources at different resolutions. The browser then picks the most appropriate one based on the device's screen density and viewport size, saving significant bandwidth.

Also, use modern image formats. WebP and AVIF offer much better compression than JPEG or PNG. You can use the <picture> element to provide these formats with a fallback.

Finally, for repeat visits, a Service Worker can provide instant loads. It's a script that acts as a proxy between your app and the network. You can implement caching strategies like "stale-while-revalidate": serve content from the cache immediately for a fast response, while simultaneously fetching an updated version in the background to cache for the next visit. This is a core feature of Progressive Web Apps (PWAs).

Try it

Open the network tab in your browser's dev tools and load a complex web app you use daily. Filter by "JS". Find the largest JavaScript file. Use a bundle analyzer tool (like webpack-bundle-analyzer or source-map-explorer) on one of your own projects to identify the largest modules in your main bundle.

Next: Data Fetching Strategies & Caching

Lock it in — apply this lesson under interview conditions.

Try a free mock interviewPractice system design problems
Previous

Frontend Build Tools & Development Workflows

Next

Data Fetching Strategies & Caching