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

Add PreloadHeroImage Optimizer transformer #5350

Merged
merged 98 commits into from
Nov 3, 2020
Merged

Conversation

schlessera
Copy link
Collaborator

@schlessera schlessera commented Sep 8, 2020

Summary

This PR adds a new PreloadHeroImage transformer.

This transformer optimizes image rendering times for hero images by adding preload and serverside-rendered <img> tags when possible. Viable hero images are <amp-img> tags, <amp-video> tags with a poster attribute as well as <amp-iframe> and <amp-video-iframe> tags with a placeholder attribute. The first viable image that is encountered is used by default, but this behavior can be overridden by adding the data-hero attribute to a maximum of two images. The preloads only work work images that don't use srcset, as that is not supported as a preload in most browsers. The serverside-rendered image will not be created for <amp-video> tags.

Fixes #5055

Checklist

  • My pull request is addressing an open issue (please create one otherwise).
  • My code is tested and passes existing tests.
  • My code follows the Engineering Guidelines (updates are often made to the guidelines, check it out periodically).

@schlessera schlessera added Optimizer WS:Perf Work stream for Metrics, Performance and Optimizer labels Sep 8, 2020
@schlessera schlessera added this to the v2.1 milestone Sep 8, 2020
@google-cla google-cla bot added the cla: yes Signed the Google CLA label Sep 8, 2020
lib/common/src/ResponseDestination.php Outdated Show resolved Hide resolved
includes/class-amp-theme-support.php Show resolved Hide resolved
lib/common/src/Url.php Outdated Show resolved Hide resolved
Comment on lines +37 to +39
list($scheme, $host, $port, $user, $pass, $path, $query, $fragment) = array_values(
array_merge(
self::URL_DEFAULT_PARTS,
Copy link
Member

Choose a reason for hiding this comment

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

This feels a bit risky as it relies on the array keys being defined in the exact same order as the items in the list().

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Well, we control both, so why wouldn't they?

lib/common/src/Url.php Outdated Show resolved Hide resolved
lib/optimizer/src/Transformer/PreloadHeroImage.php Outdated Show resolved Hide resolved
lib/optimizer/src/Transformer/PreloadHeroImage.php Outdated Show resolved Hide resolved
lib/optimizer/src/Transformer/PreloadHeroImage.php Outdated Show resolved Hide resolved
lib/optimizer/src/Transformer/PreloadHeroImage.php Outdated Show resolved Hide resolved
src/Transformer/DetermineHeroImages.php Outdated Show resolved Hide resolved
schlessera and others added 9 commits October 31, 2020 12:33
@schlessera schlessera marked this pull request as draft November 3, 2020 12:00
@westonruter
Copy link
Member

Merging for importing into amp-toolbox-php.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Signed the Google CLA Optimizer WS:Perf Work stream for Metrics, Performance and Optimizer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optimize hero images
4 participants