Course contentsShow
← Web Development
Lesson 2791 of 2,98250. Third-Party IntegrationsFree lesson

Script Tag Basics and Execution Order

How script tags load and execute in document order, blocking HTML parsing by default.

Script Tag Basics and Execution Order

You'll learn: How <script> tags load and execute in a browser, and why they block HTML parsing by default.

When a browser encounters a <script> tag while parsing your HTML document, it stops everything, downloads the script (if it has a src attribute), executes it immediately, and only then continues parsing the rest of the HTML. This is called synchronous blocking behavior.

Why This Matters for Third-Party Integrations

Think of the browser as reading your HTML like a book, line by line. When it hits a <script>, it's like encountering a mandatory detour—the browser must complete that detour before continuing to read. This ensures scripts run in the exact order they appear:

<script src="analytics-setup.js"></script>
<script src="analytics-config.js"></script>
<!-- analytics-setup.js ALWAYS runs before analytics-config.js -->

This predictability is useful when one script depends on another (like when your analytics configuration needs the core library loaded first). However, it also means a slow-loading script can freeze your entire page rendering.

Document Order Guarantees

Scripts without special attributes (async or defer) execute in document order—top to bottom. If you have three analytics scripts stacked together, the browser will:

  1. Download and execute the first
  2. Download and execute the second
  3. Download and execute the third
  4. Resume HTML parsing after the third completes

This blocking behavior is why script placement matters tremendously for page performance and user experience.

Key Takeaway: By default, <script> tags block HTML parsing and execute synchronously in document order—crucial for dependent scripts but potentially harmful to page load performance.