SyntaxStudy
Sign Up
HTML Intermediate 4 min read

The defer Attribute

Script defer

The defer attribute downloads the script in parallel with HTML parsing but delays execution until parsing is complete.

Deferred scripts execute in order, making defer safer than async for interdependent scripts.

Example
<head>
  <!-- Downloads in parallel, runs after DOM is ready, in order -->
  <script defer src="jquery.js"></script>
  <script defer src="app.js"></script>
</head>
Pro Tip

Use defer for your main application scripts — it is safer than async and avoids blocking rendering.