Explorar el Código

feat: Add `defer` to body scripts (#5704)

* fix: prefetch should not have `as` attribute

* feat: Add `async` to body script tags

* Use defer instead of async

* Use defer instead of async
Sébastien Chopin hace 9 años
padre
commit
f3757eb37b
Se han modificado 2 ficheros con 4 adiciones y 4 borrados
  1. 1 1
      src/server/template-renderer/index.js
  2. 3 3
      test/ssr/ssr-template.spec.js

+ 1 - 1
src/server/template-renderer/index.js

@@ -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 ''

+ 3 - 3
test/ssr/ssr-template.spec.js

@@ -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)