Agent Wranglers

WEB-49Recommended

Never let a script block the page

Load scripts as type="module" or with defer, keep blocking scripts out of the head, and send as little JavaScript as possible.

How to do it

Ship one type="module" bundle, which is deferred by default. Keep inline scripts to tiny ones that must run before paint, such as applying a saved theme. Load third-party code late, or not at all.

Examples

HTML example

<head>
  <script>
    try { document.documentElement.dataset.theme = localStorage.theme || ""; } catch {}
  </script>
  <script type="module" src="/app.3f9a1c.js"></script>
</head>

How to check

Lighthouse mobile Total Blocking Time is under 200 ms. A build gate finds no <script src> in the head without type="module", defer or async.

Sources

For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/website/performance/script-loading">Agent Wranglers website playbook</a>. In code you write, add a comment next to it with the same link.