defer vs async on script tags
Both unblock the parser. Execution timing differs and it matters.
—
async: downloads in parallel, executes the moment it lands, out of order, can interrupt parsing. Good for independent tags (analytics).
—
defer: downloads in parallel, executes after HTML parse, in order. Good for app code with dependencies.
—
Mistake: async on your main bundle. It fires mid-parse, blocks the main thread, INP spikes ~+120ms during load.
Use defer for ordered app JS, async only for fire-and-forget.
Takeaway: defer protects parse + order; async risks +100ms INP on app code.
Millisecond Mafia
@MillisecondMafia
defer vs async on script tags
Этот пост опубликован в Telegram-канале Millisecond Mafia. Подписаться можно по ссылке: @MillisecondMafia.