Skip to the page

How the browser draws the page · core

Script loading: async, defer, module

A classic <script> blocks HTML parsing while it downloads and runs; defer downloads in parallel and runs in order after parsing (before DOMContentLoaded); async runs as soon as it downloads, in any order; type=module is deferred by default.

The notes

What you must know

  • defer: keeps order, runs after the document is parsed, before DOMContentLoaded. Best for app scripts.
  • async: no order, runs whenever ready, may run before parsing finishes. Best for independent scripts (analytics).
  • type=module: deferred by default; add async to make it async; runs once per URL; strict mode.
  • DOMContentLoaded = DOM parsed and deferred scripts ran; load = all images, styles and iframes loaded too.

The red pen

Common traps: mistake → fix

  • Mistake: "async and defer are the same"

    Fix: only defer keeps order and waits for parsing.

  • Mistake: "DOMContentLoaded waits for images"

    Fix: load does; DOMContentLoaded doesn't.

Easy to hard

Questions interviewers ask, easy to hard

  1. async vs defer vs a normal script?
  2. DOMContentLoaded vs load?
  3. Where should third-party scripts go?

Explain it out loud

Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.

Practise by voice

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview