From b35e0b34c9dd136601335286e1ad45cee6d405e2 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Tue, 15 Dec 2020 14:30:15 +0000 Subject: [PATCH 1/3] Split preconnect and dns-prefetch into two separate links --- .../lib/transformers/GoogleFontsPreconnect.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/optimizer/lib/transformers/GoogleFontsPreconnect.js b/packages/optimizer/lib/transformers/GoogleFontsPreconnect.js index 342ad037c..bd709c6a3 100644 --- a/packages/optimizer/lib/transformers/GoogleFontsPreconnect.js +++ b/packages/optimizer/lib/transformers/GoogleFontsPreconnect.js @@ -52,14 +52,22 @@ class GoogleFontsPreconnect { if (this.isGoogleFontsLinkNode_(node)) { // Preconnect to fonts.gstatic.com, where the final fonts are downloaded. const linkPreconnect = createElement('link', { - rel: 'dns-prefetch preconnect', + rel: 'preconnect', href: 'https://fonts.gstatic.com', crossorigin: '', }); + const linkDnsPrefetch = createElement('link', { + rel: 'dns-prefetch', + href: 'https://fonts.gstatic.com', + }); const referenceNode = findMetaViewport(head); insertAfter(head, linkPreconnect, referenceNode); this.log_.debug( - 'adding ' + 'adding ' + ); + insertAfter(head, linkDnsPrefetch, referenceNode); + this.log_.debug( + 'adding ' ); // We only need 1 preconnect, so we can skip the remaining elements and return. From d187173ff4dabd3cf64cb087306ac3fd33d5f300 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Tue, 15 Dec 2020 14:31:25 +0000 Subject: [PATCH 2/3] Ensure dns-prefetch is inserted after preconnect --- packages/optimizer/lib/transformers/GoogleFontsPreconnect.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/optimizer/lib/transformers/GoogleFontsPreconnect.js b/packages/optimizer/lib/transformers/GoogleFontsPreconnect.js index bd709c6a3..b5810d01f 100644 --- a/packages/optimizer/lib/transformers/GoogleFontsPreconnect.js +++ b/packages/optimizer/lib/transformers/GoogleFontsPreconnect.js @@ -65,7 +65,7 @@ class GoogleFontsPreconnect { this.log_.debug( 'adding ' ); - insertAfter(head, linkDnsPrefetch, referenceNode); + insertAfter(head, linkDnsPrefetch, linkPreconnect); this.log_.debug( 'adding ' ); From 86736b95707573dab82b0141ca54b9085bd791b2 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Tue, 15 Dec 2020 14:31:56 +0000 Subject: [PATCH 3/3] Adapt expected output for spec tests --- .../adds_only_one_preconnect/expected_output.html | 3 ++- .../adds_preconnect_after_meta_charset/expected_output.html | 3 ++- .../expected_output.html | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/optimizer/spec/transformers/valid/GoogleFontsPreconnect/adds_only_one_preconnect/expected_output.html b/packages/optimizer/spec/transformers/valid/GoogleFontsPreconnect/adds_only_one_preconnect/expected_output.html index 7bf36a40c..c20fe2953 100644 --- a/packages/optimizer/spec/transformers/valid/GoogleFontsPreconnect/adds_only_one_preconnect/expected_output.html +++ b/packages/optimizer/spec/transformers/valid/GoogleFontsPreconnect/adds_only_one_preconnect/expected_output.html @@ -2,7 +2,8 @@ - + +