JS Guide
HomeQuestionsSearchResources
Search

Built for developers preparing for JavaScript, React & TypeScript interviews.

ResourcesQuestionsSupport
HomeQuestionsSearchProgress
HomeQuestionsperformance
PrevNext
performance
senior
rendering

What is the Critical Rendering Path and how do you optimize it?

critical-rendering-path
optimization
css
fonts
preload
Quick Answer

The Critical Rendering Path is the sequence of steps browsers take to render a page: HTML parsing, CSS parsing, render tree construction, layout, and paint. Optimize by minimizing critical resources, reducing file sizes, and removing render-blocking resources.

Detailed Explanation

Critical Rendering Path Steps:

  1. Parse HTML → DOM
  2. Parse CSS → CSSOM
  3. Combine → Render Tree
  4. Layout → Geometry calculations
  5. Paint → Draw pixels

Blocking Resources:

  • CSS blocks rendering
  • JavaScript blocks parsing
  • Fonts can cause FOIT/FOUT

Optimization Strategies:

  1. Minimize critical resources
  2. Defer non-critical CSS/JS
  3. Inline critical CSS
  4. Async/defer scripts
  5. Preload important resources
  6. Optimize font loading

Code Examples

Optimizing resource loading
<!DOCTYPE html>
<html>
<head>
  <!-- Preconnect to critical origins -->
  <link rel="preconnect" href="https://fonts.googleapis.com">
  <link rel="preconnect" href="https://api.example.com">
  
  <!-- Preload critical resources -->
  <link rel="preload" href="/fonts/main.woff2" as="font" type="font/woff2" crossorigin>
  <link rel="preload" href="/hero.jpg" as="image">
  
  <!-- Critical CSS inlined -->
  <style>
    /* Above-the-fold styles only */
    body { margin: 0; font-family: system-ui; }
    .hero { height: 100vh; background: #f0f0f0; }
    .nav { position: fixed; top: 0; width: 100%; }
  </style>
  
  <!-- Non-critical CSS loaded asynchronously -->
  <link rel="preload" href="/styles.css" as="style" onload="this.onload=null;this.rel='stylesheet'">
  <noscript><link rel="stylesheet" href="/styles.css"></noscript>
  
  <!-- Scripts with appropriate loading strategy -->
  <script src="/critical.js"></script> <!-- Blocking if needed -->
  <script src="/analytics.js" async></script> <!-- Independent -->
  <script src="/app.js" defer></script> <!-- After DOM -->
</head>
<body>
  <!-- Content... -->
</body>
</html>

Resources

Web.dev - Critical Rendering Path

article

Critical CSS Tool

docs

Related Questions

What are Core Web Vitals and why do they matter?

junior
metrics

What is the difference between SSR, SSG, and CSR?

mid
rendering
Previous
How do service workers improve performance and what caching strategies exist?
Next
How do you set up performance monitoring for production applications?