Skip to content

Commit

Permalink
feat: Add defer to body scripts (#5704)
Browse files Browse the repository at this point in the history
* fix: prefetch should not have `as` attribute

* feat: Add `async` to body script tags

* Use defer instead of async

* Use defer instead of async
  • Loading branch information
Atinux authored and yyx990803 committed May 22, 2017
1 parent 05195b8 commit f3757eb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/server/template-renderer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export default class TemplateRenderer {
const async = this.getUsedAsyncFiles(context)
const needed = [initial[0]].concat(async || [], initial.slice(1))
return needed.filter(isJS).map(file => {
return `<script src="${this.publicPath}/${file}"></script>`
return `<script src="${this.publicPath}/${file}" defer></script>`
}).join('')
} else {
return ''
Expand Down
6 changes: 3 additions & 3 deletions test/ssr/ssr-template.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,10 @@ describe('SSR: template option', () => {
// state should be inlined before scripts
`<script>window.${options.stateKey || '__INITIAL_STATE__'}={"a":1}</script>` +
// manifest chunk should be first
`<script src="/manifest.js"></script>` +
`<script src="/manifest.js" defer></script>` +
// async chunks should be before main chunk
`<script src="/0.js"></script>` +
`<script src="/main.js"></script>` +
`<script src="/0.js" defer></script>` +
`<script src="/main.js" defer></script>` +
`</body></html>`

createClientManifestAssertions(true)
Expand Down

0 comments on commit f3757eb

Please sign in to comment.