-
Notifications
You must be signed in to change notification settings - Fork 384
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
Add rel=preconnect link for AMP CDN #3253
Conversation
$links = [ | ||
'preconnect' => [ | ||
// Include preconnect link for AMP CDN for browsers that don't support preload. | ||
AMP_DOM_Utils::create_node( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only room for improvement here is that I'd like it if the page already had this link that it would be prevented from being duplicated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would then come from a third-party plugin/theme instead? It would be difficult to detect, it might be easier to sanitize the duplicate away instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potentially. We actually can detect because we gather up a list of all the links right here. So we could just skip adding it if it already exists.
Aside: There is also a need to remove component scripts that do not exist among $script_handles
, to remove scripts that are not relevant to the page (in case someone manually adds a script which turns out to not be relevant to the current page). See #3489.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In practice there should not be duplicates. After thinking about it more, it seems wasteful to detect for a duplicate link[rel=preconnect]
for AMP, and it doesn't hurt to have it duplicated in the first place.
06394b5
to
3a66b1e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Ship it.
In a support topic I found out that Lighthouse audits are flagging the lack of
rel=preconnect
links for https://cdn.ampproject.org:This currently is not part of the AMP optimization guide, and I thought it was unnecessary because there is already more-specific
preload
links, like:I checked with @sebastianbenz and he pointed out that not all browsers support
rel=preload
, so adding arel=preconnect
link would be a good thing to do.