perfmedium
What is the difference between a plain script tag, defer and async?
Answer
A plain <script> blocks HTML parsing while it downloads and runs. defer downloads in parallel and runs after parsing completes, preserving document order — the right default for app code. async also downloads in parallel but runs the moment it arrives, so order isn't guaranteed; it suits independent third-party snippets like analytics.
Points an interviewer listens for
- Plain: blocks the parser
- defer: parallel download, runs after parse, keeps order
- async: parallel download, runs on arrival, order not guaranteed
- defer for app code, async for independent third-party
Reported at
Similar questions have been reported by candidates at Northcorp Software, Cognizant, Pocket FM, Tekion, Tekwissen, Accenture.
Now try answering it out loud
Interview practice mode times your spoken answer and checks it against the points above.
Practise this question