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

Split preconnect and dns-prefetch into two separate links #1065

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: 10 additions & 2 deletions packages/optimizer/lib/transformers/GoogleFontsPreconnect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <link rel="dns=prefetch preconnect" href="' + linkPreconnect.attribs.href + '">'
'adding <link rel="preconnect" href="' + linkPreconnect.attribs.href + '" crossorigin>'
);
insertAfter(head, linkDnsPrefetch, linkPreconnect);
this.log_.debug(
'adding <link rel="dns-prefetch" href="' + linkDnsPrefetch.attribs.href + '">'
);

// We only need 1 preconnect, so we can skip the remaining elements and return.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,minimum-scale=1">
<link rel="dns-prefetch preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="dns-prefetch" href="https://fonts.gstatic.com">
<script async src="https://cdn.ampproject.org/v0.js"></script>
<script async custom-element="amp-experiment" src="https://cdn.ampproject.org/v0/amp-experiment-0.1.js"></script>
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,minimum-scale=1">
<link rel="dns-prefetch preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="dns-prefetch" href="https://fonts.gstatic.com">
<script async src="https://cdn.ampproject.org/v0.js"></script>
<script async custom-element="amp-experiment" src="https://cdn.ampproject.org/v0/amp-experiment-0.1.js"></script>
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<html >
<head>
<meta name="viewport" content="width=device-width,minimum-scale=1">
<link rel="dns-prefetch preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="dns-prefetch" href="https://fonts.gstatic.com">
<script async src="https://cdn.ampproject.org/v0.js"></script>
<script async custom-element="amp-experiment" src="https://cdn.ampproject.org/v0/amp-experiment-0.1.js"></script>
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;
Expand Down