Frontend School
DashboardProblemsLearnPracticeMock InterviewReportsStatsBuy Credits
DashboardProblemsLearnPracticeMock Interview
Frontend System Design Roadmap
  1. 1.HTTP/1.1 vs HTTP/2 vs HTTP/3 (QUIC)
  2. 2.TCP and TLS Handshakes: Connection Setup Costs
  3. 3.Browser Network Stack and Connection Pooling
  4. 4.GET vs POST and Idempotency in HTTP
  5. 5.The Critical Rendering Path (CRP)
  6. 6.DOM, CSSOM and the Render Tree
  7. 7.Layout, Paint and Compositing
  8. 8.Reflows and Repaints Explained
  9. 9.Event Loop: Call Stack, Task and Microtask Queues
  10. 10.Async JavaScript: Promises and async/await
  11. 11.Web Workers: Multi-threading in the Browser
  12. 12.Browser Storage: Cookies, Web Storage, IndexedDB
  13. 13.Client-Side Storage: Limits and Security Risks
  14. 14.Choosing the Right Client-Side Storage
  15. 15.HTTP Caching: Cache-Control, ETag, Last-Modified
  16. 16.Browser-Level Caching Mechanisms
  17. 17.Cache Invalidation for Frontend Apps
  18. 18.Structuring a Large Single-Page App
  19. 19.Component-Based Architecture Principles
  20. 20.Props, State and Component Lifecycle
  21. 21.Module Bundling Basics
  22. 22.Core Web Vitals: LCP, INP and CLS
  23. 23.FCP and Time to Interactive (TTI) Explained
  24. 24.Measuring Performance: Lighthouse and WebPageTest
  25. 25.Asset Compression and Minification Basics
  26. 26.What Is a CDN and How Does It Work?
  27. 27.CDN Benefits: Latency, Availability, Offload
  28. 28.CDN Cache Behavior and Invalidation
  29. 29.Global State vs Local Component State
  30. 30.State Patterns: Redux, Zustand and Context
  31. 31.Data Fetching: React Query and SWR
  32. 32.Immutable Data in Frontend State
  33. 33.SSR vs CSR: Rendering Trade-offs
  34. 34.Hydration and Time to First Byte (TTFB)
  35. 35.Static Site Generation (SSG) for Speed and SEO
  36. 36.Incremental Static Regeneration (ISR)
  37. 37.Micro-Frontends: Core Principles
  38. 38.Micro-Frontend Integration Strategies
  39. 39.Communication Between Micro-Frontends
  40. 40.Micro-Frontends: Pros and Cons for Large Teams
  41. 41.Real-Time: Polling, SSE and WebSockets
  42. 42.Real-Time Use Cases: Chat, Alerts, Live Data
  43. 43.Designing a Real-Time Data Flow
  44. 44.Scaling WebSocket Connections
  45. 45.Responsive Images: srcset, sizes and picture
  46. 46.Modern Image Formats: WebP, AVIF, JPEG XL
  47. 47.Lazy Loading Images and Videos
  48. 48.Video Streaming: HLS, DASH, Adaptive Bitrate
  49. 49.REST and GraphQL for Frontend Engineers
  50. 50.Batching, Throttling and Debouncing API Calls
  51. 51.Handling API Errors in the Frontend
  52. 52.Authentication Flows: OAuth and JWT
  53. 53.Global Error Boundaries in React
  54. 54.Error Reporting: Sentry and LogRocket
  55. 55.Graceful Degradation and Fallback UIs
  56. 56.Real User Monitoring (RUM)
  57. 57.CORS: Cross-Origin Resource Sharing
  58. 58.Preventing XSS (Cross-Site Scripting)
  59. 59.CSRF Protection for Frontend Apps
  60. 60.Content Security Policy (CSP)
  61. 61.Storing Auth Tokens: Cookies vs localStorage
  62. 62.PWA Manifest and Installability
  63. 63.Service Workers: Lifecycle and Caching Strategies
  64. 64.Offline Support and Background Sync
  65. 65.Push Notifications for Web Apps
  66. 66.Webpack vs Vite vs Parcel
  67. 67.Code Splitting, Tree Shaking, Asset Optimization
  68. 68.Module Resolution and Hot Module Replacement
  69. 69.Monorepo Tooling: Nx and Lerna
  70. 70.Atomic Design for Component Libraries
  71. 71.Theming and Customization in Design Systems
  72. 72.Accessibility in Component Libraries
  73. 73.Component Library Docs, Testing and Versioning
  74. 74.Publishing and Consuming a Component Library
  75. 75.Full-Text Search: Levenshtein and Fuzzy Matching
  76. 76.Indexing Large Datasets in the Browser
  77. 77.Search Performance: Debouncing and Web Workers
  78. 78.Integrating Backend Search Services
  79. 79.Choosing a Chart Library: D3, Chart.js, Recharts
  80. 80.Rendering Large Datasets: Canvas vs SVG
  81. 81.Interactive, Responsive Data Visualizations
  82. 82.Data Fetching and Aggregation for Dashboards
  83. 83.A/B Test Design and Rollout Strategies
  84. 84.Client-Side vs Server-Side A/B Testing
  85. 85.Feature Flags and Remote Configuration
  86. 86.Experiment Data Collection and Analytics
Frontend System Design Roadmap
05

Frontend System Design · Lesson 5 of 86 · 5 min

The Critical Rendering Path (CRP)

This is how you explain why a page is slow and what you'd do about it—a fundamental performance question.

When the browser receives HTML, it follows a sequence of steps to turn that code into pixels on the screen. This sequence is the Critical Rendering Path. If any step is slow or blocked, the user sees a blank page. Your job is to make this path as short as possible.

The path has six main steps. You should be able to name and explain each one.

  1. DOM Construction: The browser parses HTML into a tree of objects, the Document Object Model.
  2. CSSOM Construction: The browser parses CSS into a tree of styles, the CSS Object Model.
  3. Render Tree Construction: The browser combines the DOM and CSSOM into a Render Tree. This tree only includes what will be visible on the page. Nodes like <head> or elements with display: none are omitted.
  4. Layout: The browser calculates the exact size and position of every object in the Render Tree. This is also called "reflow".
  5. Paint: The browser draws the pixels for each element, layer by layer.
  6. Compositing: The browser combines the painted layers in the correct order to display the final image on screen.

This entire process is what blocks the user from seeing content.

Find the render-blocking resources

Anything the browser needs to construct the Render Tree is a "critical" resource. By default, both CSS and JavaScript are treated as critical and can block rendering.

CSS is render-blocking. The browser won't paint any pixels until it has constructed the CSSOM. It needs to know how every element will be styled before it can start drawing them. This is why a <link rel="stylesheet"> in your <head> will pause rendering until the file is downloaded and parsed.

JavaScript is parser-blocking. When the HTML parser sees a <script> tag, it stops parsing HTML. It must download, parse, and execute the script before it can continue building the DOM. The browser does this because JavaScript can modify the DOM and CSSOM (document.write is the classic example), so it has to wait and see what the script does.

The interview question: "A user reports seeing a blank white screen for three seconds after navigating to our homepage. Where do you start looking?"

Your answer starts here: "I'd first check for render-blocking resources in the <head> of the document. A large CSS file or a synchronous JavaScript file could be delaying the initial render." Then, you'd use browser dev tools to confirm.

How to unblock the path with async and defer

You can't eliminate blocking resources, but you can control how they block. For JavaScript, you use the async and defer attributes on the <script> tag.

defer: The script is downloaded in parallel with HTML parsing, but it's only executed after the parser finishes, just before the DOMContentLoaded event. defer scripts are executed in the order they appear in the HTML. This is the best choice for scripts that need to access the full DOM.

async: The script is downloaded in parallel. As soon as it finishes downloading, HTML parsing is paused, and the script is executed. There is no guarantee async scripts will run in any particular order. Use this for independent, third-party scripts like analytics that don't depend on the DOM or other scripts.

The trap: Never use async for a script that modifies the DOM unless you are certain the elements it needs will be present. It's a race condition. If the script finishes downloading before the parser has created the target DOM node, your script will fail. Use defer for that.

For CSS, you can split your styles into critical and non-critical. Critical CSS contains the minimal styles needed to render the "above-the-fold" content. You should inline this directly in a <style> tag in the <head> for the fastest possible first paint.

Load the rest of your CSS in a non-blocking way. A common technique is to use a <link> with a media attribute that doesn't match the current context (like media="print"), then switch it to all once it loads.

Here is a single example showing these optimizations in action.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Optimized CRP</title>

    <!-- 1. Inline critical CSS for the fastest first paint -->
    <style>
      body { font-family: sans-serif; background: #EEE; }
      h1 { color: #333; }
    </style>

    <!-- 2. Load non-critical CSS asynchronously -->
    <link rel="stylesheet" href="non-critical.css" media="print" onload="this.media='all'">
    <noscript><link rel="stylesheet" href="non-critical.css"></noscript>

    <!-- 3. Use 'async' for independent 3rd-party scripts -->
    <script async src="analytics.js"></script>

    <!-- 4. Use 'defer' for scripts that need the DOM -->
    <script defer src="app.js"></script>
</head>
<body>
    <h1>Welcome</h1>
    <p>This content renders almost instantly because critical styles are inlined and scripts are non-blocking.</p>
</body>
</html>

What happens after the first paint

Optimizing the CRP is mostly about the initial load. But the same steps—Layout, Paint, Compositing—happen again every time you change something on the page with JavaScript. Triggering them unnecessarily causes jank and a slow user experience.

A common performance killer is layout thrashing. This happens when you repeatedly read a geometric property from the DOM (like element.offsetHeight) and then write a style that changes geometry in a loop.

Each time you read a property like offsetHeight, the browser may have to perform a layout to give you an up-to-date value. If you do this right after making a change, you force a synchronous reflow.

// BAD: Causes layout thrashing
function resizeAllParagraphs(paragraphs) {
  for (let i = 0; i < paragraphs.length; i++) {
    // Read (triggers layout)
    const width = paragraphs[i].offsetWidth; 
    // Write (invalidates layout)
    paragraphs[i].style.width = (width / 2) + 'px';
  }
}

// GOOD: Batches reads and writes
function resizeAllParagraphsFixed(paragraphs) {
  const widths = [];
  // Read all values first
  for (let i = 0; i < paragraphs.length; i++) {
    widths.push(paragraphs[i].offsetWidth);
  }
  // Then write all values
  for (let i = 0; i < paragraphs.length; i++) {
    paragraphs[i].style.width = (widths[i] / 2) + 'px';
  }
}

By batching your reads and writes, you allow the browser to perform a single layout calculation instead of one for each iteration of the loop.

Try it

Open the Chrome DevTools on a complex news or e-commerce site. Go to the "Performance" tab and record a page load. Find the "Main" thread in the flame chart and identify the long tasks. Look for the events corresponding to the CRP: "Parse HTML", "Recalculate Style", "Layout", "Paint", and "Composite Layers".

Next: DOM, CSSOM and the Render Tree

Lock it in — apply this lesson under interview conditions.

Try a free mock interviewPractice system design problems
Previous

GET vs POST and Idempotency in HTTP

Next

DOM, CSSOM and the Render Tree