Skip to content

Move hero image preload out of experimental#814

Merged
sebastianbenz merged 4 commits intomasterfrom
hero-experimental
Jun 3, 2020
Merged

Move hero image preload out of experimental#814
sebastianbenz merged 4 commits intomasterfrom
hero-experimental

Conversation

@sebastianbenz
Copy link
Copy Markdown
Collaborator

@sebastianbenz sebastianbenz commented May 29, 2020

This also changes the transformer to only run if there a no pre-existing image preloads.

Copy link
Copy Markdown
Collaborator

@patrickkettner patrickkettner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

}
}
return false;
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continuing my series of "unhelpful comments that make the code less readable"...

return [...head.children].any(this.isImagePreload)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the destructuring? I think head.children.some(this.isImagePreload); does the trick as well (and is easy to read).

<link rel="preload" href="https://cdn.ampproject.org/v0.js" as="script">
<script data-auto async src="https://cdn.ampproject.org/v0.js"></script>
<script async src="https://cdn.ampproject.org/v0/amp-video-0.1.js" custom-element="amp-video"></script>
<link rel="preload" href="https://amp.dev/static/samples/img/tokyo.jpg" as="image" data-hero>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just for my own edification - what is the purpose of the data attr?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For being able to track which images have been identified as hero images

@sebastianbenz sebastianbenz merged commit 4b59cdc into master Jun 3, 2020
@sebastianbenz sebastianbenz deleted the hero-experimental branch June 3, 2020 16:51
@westonruter
Copy link
Copy Markdown
Member

For images that have srcset and sizes, this may not work as expected: #823.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants