0
0
HTMLmarkup~8 mins

How browsers read HTML - Performance Optimization Steps

Choose your learning style9 modes available
Performance: How browsers read HTML
HIGH IMPACT
This affects how quickly the browser can start rendering the page and show content to the user.
Loading a simple webpage with scripts and styles
HTML
<!DOCTYPE html>
<html lang="en">
<head>
  <link rel="stylesheet" href="styles.css">
  <script src="large-script.js" defer></script>
</head>
<body>
  <h1>Hello World</h1>
</body>
</html>
Using defer lets the browser download the script without blocking HTML parsing, so content appears faster.
📈 Performance GainFirst paint happens sooner, reducing blocking time by 200-500ms.
Loading a simple webpage with scripts and styles
HTML
<!DOCTYPE html>
<html lang="en">
<head>
  <script src="large-script.js"></script>
  <link rel="stylesheet" href="styles.css">
</head>
<body>
  <h1>Hello World</h1>
</body>
</html>
The browser blocks rendering while downloading and executing the script before it can show any content.
📉 Performance CostBlocks rendering until script loads and executes, delaying first paint by 200-500ms depending on script size.
Performance Comparison
PatternDOM OperationsReflowsPaint CostVerdict
Synchronous script in headBlocks DOM building until script loadsTriggers multiple reflows after scriptDelays paint until script finishes[X] Bad
Defer script in headDOM builds continuously while script downloadsSingle reflow after script executesPaint happens earlier[OK] Good
Rendering Pipeline
The browser reads HTML from top to bottom, parsing tags and building the DOM tree. When it encounters scripts without defer or async, it pauses parsing to download and run them. Stylesheets block rendering until loaded to avoid showing unstyled content. After parsing, the browser calculates styles, layouts, paints pixels, and composites layers.
HTML Parsing
Style Calculation
Layout
Paint
Composite
⚠️ BottleneckHTML Parsing is blocked by synchronous scripts, delaying all subsequent stages.
Core Web Vital Affected
LCP
This affects how quickly the browser can start rendering the page and show content to the user.
Optimization Tips
1Avoid placing scripts without defer or async in the head to prevent blocking HTML parsing.
2Load CSS early to avoid delaying rendering and causing visual flashes.
3Use defer or async attributes on scripts to improve page load speed and reduce blocking.
Performance Quiz - 3 Questions
Test your performance knowledge
What happens when a browser encounters a script tag without defer or async while reading HTML?
AIt continues parsing HTML while downloading the script in the background.
BIt pauses HTML parsing to download and execute the script immediately.
CIt ignores the script until the entire HTML is parsed.
DIt downloads the script after the page finishes loading.
DevTools: Performance
How to check: Open DevTools, go to Performance tab, record page load, and look for long tasks blocking HTML parsing and scripting.
What to look for: Look for 'Parse HTML' and 'Evaluate Script' tasks that block rendering and delay first paint.