Skip to content

Commit

Permalink
Switch from defer to async (#10143)
Browse files Browse the repository at this point in the history
  • Loading branch information
Timer authored and ijjk committed Jan 17, 2020
1 parent 53d5bd8 commit 08f241f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
12 changes: 6 additions & 6 deletions packages/next/pages/_document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ export class NextScript extends Component<OriginProps> {

return (
<script
defer
async
key={bundle.file}
src={`${assetPrefix}/_next/${encodeURI(
bundle.file
Expand Down Expand Up @@ -611,7 +611,7 @@ export class NextScript extends Component<OriginProps> {
file
)}${_devOnlyInvalidateCacheQueryString}`}
nonce={this.props.nonce}
defer
async
crossOrigin={this.props.crossOrigin || process.crossOrigin}
{...modernProps}
/>
Expand Down Expand Up @@ -720,7 +720,7 @@ export class NextScript extends Component<OriginProps> {

const pageScript = [
<script
defer
async
data-next-page={page}
key={page}
src={
Expand All @@ -734,7 +734,7 @@ export class NextScript extends Component<OriginProps> {
/>,
process.env.__NEXT_MODERN_BUILD && (
<script
defer
async
data-next-page={page}
key={`${page}-modern`}
src={
Expand All @@ -753,7 +753,7 @@ export class NextScript extends Component<OriginProps> {

const appScript = [
<script
defer
async
data-next-page="/_app"
src={
assetPrefix +
Expand All @@ -767,7 +767,7 @@ export class NextScript extends Component<OriginProps> {
/>,
process.env.__NEXT_MODERN_BUILD && (
<script
defer
async
data-next-page="/_app"
src={
assetPrefix +
Expand Down
6 changes: 3 additions & 3 deletions test/integration/production/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -678,21 +678,21 @@ describe('Production Usage', () => {
}
})

it('should have defer on all script tags', async () => {
it('should have async on all script tags', async () => {
const html = await renderViaHTTP(appPort, '/')
const $ = cheerio.load(html)
let missing = false

for (const script of $('script').toArray()) {
// application/json doesn't need defer
// application/json doesn't need async
if (
script.attribs.type === 'application/json' ||
script.attribs.src.includes('polyfills')
) {
continue
}

if (script.attribs.async === '' || script.attribs.defer !== '') {
if (script.attribs.defer === '' || script.attribs.async !== '') {
missing = true
}
}
Expand Down

0 comments on commit 08f241f

Please sign in to comment.