Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from defer to async #10143

Merged
merged 2 commits into from
Jan 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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