Menu

async vs defer: Why Script Order Breaks Your Page
📰

async vs defer: Why Script Order Breaks Your Page

DEV Community: html·Mohsen Fallahnejad·8 days ago
#2NYKejsv
#devto2#devto#dev#async#scripts
Long article (709 words) — no AI summary yet.
Reading 0:00
15s threshold

You add async to two script tags to speed up the page. Now it breaks one load in ten with $ is not defined . The plugin ran before the library it needs.

async vs defer is a question about when a script runs, not how it downloads.

The mental model

Both download in the background. async runs the moment it lands. defer waits in line until the HTML is done.

Picture food deliveries arriving while you set a table. async serves each dish the second it comes through the door, in whatever order the drivers arrive. defer puts every dish on a shelf and serves them in menu order once the table is fully set.

How it works

The browser reads your HTML top to bottom and builds the page as it goes. That's called parsing .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.