Loading...
Loading...
Parsing Pipeline is the process of transforming HTML/CSS bytes into data structures (DOM and CSSOM) that the browser can work with. Understanding this process is critical for optimizing page load performance.
Bytes: 3C 68 31 3E ...
↓ (Character Encoding)
Characters: <h1>Hello</h1>
Character Encoding Detection:
charset=utf-8<meta charset="utf-8">HTML parser converts characters into tokens:
<div class="container">
<h1>Title</h1>
<p>Text</p>
</div>
Tokens:
StartTag: div (attributes: class="container")
StartTag: h1
Character: Title
EndTag: h1
StartTag: p
Character: Text
EndTag: p
EndTag: div
Tokens are transformed into DOM nodes and DOM tree is built:
Preload Scanner works in parallel with HTML parser and preloads resources:
<html>
<head>
<!-- Parser here -->
<link rel="stylesheet" href="style.css">
<script src="app.js"></script>
</head>
<body>
<img src="hero.jpg"> <!-- Preload Scanner already found this! -->
What Preload Scanner finds:
<link rel="stylesheet"><script src><img src><link rel="preload">body {
color: blue;
font-size: 16px;
}
Tokens:
Selector: body
Property: color
Value: blue
Property: font-size
Value: 16px
CSS blocks rendering!
<head>
<link rel="stylesheet" href="style.css"> <!-- Blocks! -->
</head>
<body>
<!-- Content won't render until CSS loads -->
Solution — Media Queries:
<link rel="stylesheet" href="print.css" media="print"> <!-- Doesn't block screen -->
<link rel="stylesheet" href="mobile.css" media="(max-width: 600px)">
DOM + CSSOM = Render Tree
<div style="display:none">Hidden</div>
<div class="visible">Visible</div>
Render Tree contains only visible elements:
display: none — not in Render Treevisibility: hidden — in Render Tree (takes space)<head>, <script>, <meta> — not in Render TreeModern browsers use speculative parsing:
<script src="slow.js"></script> <!-- Blocks parsing -->
<img src="image1.jpg">
<img src="image2.jpg">
Without Speculative Parsing:
<script>With Speculative Parsing:
<script>image1.jpg, image2.jpg and starts loading!CSS blocks rendering. Use critical CSS inline for above-the-fold content.
Don't block parsing. <script defer> doesn't block.
Use <link rel="preload"> for critical resources.
Completely breaks Speculative Parsing!
Summary:
Parsing Pipeline is a complex multi-stage process with many optimizations (Preload Scanner, Speculative Parsing). Understanding this process helps write HTML/CSS that loads faster.