George Paouris
George Paouris

Reputation: 645

How defer script is different that preload link?

Preload: fetch a CSS stylesheet and apply it at some later time, fetch a JavaScript asset and execute it later, and so on. Preload fetches do not block the document load event and allow the application to determine which resources are applied, when they are executed, and in which order.

Defer: The "defer" preloads during HTML parsing and will only execute it after the parser has completed.

I cant understand the differences in both concepts. Both fetch stuff asynchronously without blocking the parser and afterwards both can be executed when the parser is done.

So is there any difference at all?

Upvotes: 9

Views: 2609

Answers (2)

Obinna Obi-Akwari
Obinna Obi-Akwari

Reputation: 46

You use "defer" for scripts that need to be executed after the HTML document is parsed, and "preload" when you want to load resources much earlier.

Upvotes: 0

Bottle Of Soul
Bottle Of Soul

Reputation: 1

Preload fetches do not block the document load event and allow the application to determine which resources are applied, when they are executed, and in which order. Defer: The "defer" preloads during HTML parsing and will only execute it after the parser has completed.

Upvotes: 0

Related Questions