Next.js: Use defer instead of async

Created on 11 Mar 2019  路  2Comments  路  Source: vercel/next.js

Feature request

Is there any reason to use async instead of defer in script tags here https://github.com/zeit/next.js/blob/canary/packages/next/pages/_document.js ?

Scripts marked defer are executed (after parsing completes) in the order which they are defined in the markup.
Maybe in your case it doesn't matter what to use, but it could be helpful when i.e. you want to load some polyfill before other scripts, you mark it as defer not to block page rendering, but you cannot be sure it will be executed before other scripts, because they are marked async, and they can be executed before the deferred one.

It sounds like an easy change.

What do you think?

Most helpful comment

Copypasting from loadable-components:

  • 馃憤 defer would maintain (non extracted from JS) CSS order
  • 馃憤 defer would wait for HTML to finish parse before React would try to hydrate into the incomplete tree
  • 馃憥 defer would maintain JS order, but it's, actually, webpack's job - it will _execute_ them.
  • 馃憥 defer would have lower loading priority, so you will have to prefetch the same script to load it prior images and other heavy content.

All 2 comments

Copypasting from loadable-components:

  • 馃憤 defer would maintain (non extracted from JS) CSS order
  • 馃憤 defer would wait for HTML to finish parse before React would try to hydrate into the incomplete tree
  • 馃憥 defer would maintain JS order, but it's, actually, webpack's job - it will _execute_ them.
  • 馃憥 defer would have lower loading priority, so you will have to prefetch the same script to load it prior images and other heavy content.

Excellent point about the script order not actually being important. The timing of when webpackJsonp() gets invoked seems like something nobody should be relying on anyway.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sospedra picture sospedra  路  3Comments

renatorib picture renatorib  路  3Comments

irrigator picture irrigator  路  3Comments

flybayer picture flybayer  路  3Comments

timneutkens picture timneutkens  路  3Comments