Performance: How browsers read HTML
HIGH IMPACT
This affects how quickly the browser can start rendering the page and show content to the user.
<!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>
<!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>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Synchronous script in head | Blocks DOM building until script loads | Triggers multiple reflows after script | Delays paint until script finishes | [X] Bad |
| Defer script in head | DOM builds continuously while script downloads | Single reflow after script executes | Paint happens earlier | [OK] Good |