From 0bfcaef578e5aa58b6cfdb77a6f5f1b40f76ed34 Mon Sep 17 00:00:00 2001 From: Charles Lyding <19598772+clydin@users.noreply.github.com> Date: Mon, 15 Jul 2019 12:45:28 -0400 Subject: [PATCH] feat(@angular-devkit/build-angular): add defer attributes to classic scripts This change synchronizes the behavior of classic scripts and module scripts (`type="module"`). Module scripts are deferred by default. Also, certain injected scripts are not considered module scripts even in a ES2015+ build due to the strict mode behavior of module scripts. Deferring such scripts also ensures consistent execution in those scenarios. --- .../index-file/augment-index-html.ts | 6 ++- .../index-file/augment-index-html_spec.ts | 16 +++---- .../test/browser/cross-origin_spec_large.ts | 30 ++++++------- .../test/browser/index_spec_large.ts | 42 +++++++++---------- .../test/browser/scripts-array_spec_large.ts | 12 +++--- .../test/browser/service-worker_spec_large.ts | 4 +- .../test/browser/styles_spec_large.ts | 12 +++--- .../test/dev-server/index_spec_large.ts | 12 +++--- .../e2e/tests/basic/scripts-array.ts | 12 +++--- .../e2e/tests/basic/styles-array.ts | 8 ++-- tests/legacy-cli/e2e/tests/build/polyfills.ts | 8 ++-- .../e2e/tests/build/styles/extract-css.ts | 20 ++++----- tests/legacy-cli/e2e/tests/misc/support-ie.ts | 34 +++++++-------- .../e2e/tests/misc/support-safari-10.1.ts | 22 +++++----- .../e2e/tests/third-party/bootstrap.ts | 18 ++++---- 15 files changed, 130 insertions(+), 126 deletions(-) diff --git a/packages/angular_devkit/build_angular/src/angular-cli-files/utilities/index-file/augment-index-html.ts b/packages/angular_devkit/build_angular/src/angular-cli-files/utilities/index-file/augment-index-html.ts index 3b42e21df687..bc1591bad662 100644 --- a/packages/angular_devkit/build_angular/src/angular-cli-files/utilities/index-file/augment-index-html.ts +++ b/packages/angular_devkit/build_angular/src/angular-cli-files/utilities/index-file/augment-index-html.ts @@ -150,10 +150,14 @@ export async function augmentIndexHtml(params: AugmentIndexHtmlOptions): Promise const isModuleType = moduleFiles.some(scriptPredictor); if (isNoModuleType && !isModuleType) { - attrs.push({ name: 'nomodule', value: null }); + attrs.push({ name: 'nomodule', value: null }, { name: 'defer', value: null }); } else if (isModuleType && !isNoModuleType) { attrs.push({ name: 'type', value: 'module' }); + } else { + attrs.push({ name: 'defer', value: null }); } + } else { + attrs.push({ name: 'defer', value: null }); } if (params.sri) { diff --git a/packages/angular_devkit/build_angular/src/angular-cli-files/utilities/index-file/augment-index-html_spec.ts b/packages/angular_devkit/build_angular/src/angular-cli-files/utilities/index-file/augment-index-html_spec.ts index fb8a444d9063..269c0ef43c55 100644 --- a/packages/angular_devkit/build_angular/src/angular-cli-files/utilities/index-file/augment-index-html_spec.ts +++ b/packages/angular_devkit/build_angular/src/angular-cli-files/utilities/index-file/augment-index-html_spec.ts @@ -41,9 +41,9 @@ describe('augment-index-html', () => {
- - - + + +