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 experimental amp-img -> img transformation #859

Merged
merged 9 commits into from
Jul 15, 2020
Merged

Conversation

sebastianbenz
Copy link
Collaborator

@sebastianbenz sebastianbenz commented Jul 9, 2020

Introduce data-hero attribute which will disable auto hero detection.

@@ -110,8 +110,7 @@ function maybeAddSizerInto(node, layout, width, height) {
sizer = createIntrinsicSizer(width, height);
}
if (sizer) {
const referenceNode = node.firstChild;
insertBefore(node, sizer, referenceNode);
appendChild(node, sizer);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Looks like the sizer needs to be added after the img.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sizer always goest first for responsive. Is there a bug you're seeing when sizer is first?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hm. Not sure what I tested there. All good with sizer first.

@@ -110,8 +110,7 @@ function maybeAddSizerInto(node, layout, width, height) {
sizer = createIntrinsicSizer(width, height);
}
if (sizer) {
const referenceNode = node.firstChild;
insertBefore(node, sizer, referenceNode);
appendChild(node, sizer);
Copy link
Contributor

Choose a reason for hiding this comment

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

Sizer always goest first for responsive. Is there a bug you're seeing when sizer is first?

return;
}
const imgNode = createElement('img', {
class: 'class=i-amphtml-fill-content i-amphtml-replaced-content',
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
class: 'class=i-amphtml-fill-content i-amphtml-replaced-content',
class: 'i-amphtml-fill-content i-amphtml-replaced-content',

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

generateImg(node) {
if (!this.experimentImg) {
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we were only going to do this transform for amp-imgs that have a data-hero attr set. Since we can't guarantee loading=lazy behavior for most browsers yet, we don't want to load a bunch of far-from-viewport images.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Introduce a max upper bound of 2 hero images and switched to loading=eager for these.

This commit introduces the data-hero attribute as a means to explicitly
markup hero amp-img or amp-iframe elemenents.

Other changes:

* don't bail out if there are any kind of image preloads, instead check
the img src to avoid duplicates
* use loading=eager instead of loading=lazy
@sebastianbenz sebastianbenz requested a review from jridgewell July 15, 2020 12:45
@sebastianbenz
Copy link
Collaborator Author

Adressed the comments, also:

  • introduce data-hero attribute which will disable auto hero detection
  • don't bail out if there are any kind of image preloads, instead check
    the img src to avoid duplicates
  • use loading=eager instead of loading=lazy

PTAL

const imgNode = createElement('img', {
class: 'i-amphtml-fill-content i-amphtml-replaced-content',
decoding: 'async',
loading: 'eager',
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can drop this attr.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

@sebastianbenz sebastianbenz merged commit 6f5d9dd into main Jul 15, 2020
@sebastianbenz sebastianbenz deleted the experiment-img branch July 15, 2020 18:35
@sebastianbenz
Copy link
Collaborator Author

@jridgewell Thanks for the review!

tharders pushed a commit that referenced this pull request Aug 17, 2020
This commit introduces the data-hero attribute as a means to explicitly
markup hero amp-img or amp-iframe elemenents.

Other changes:

* don't bail out if there are any kind of image preloads, instead check
the img src to avoid duplicates
* don't use loading=lazy
* print warning if there are too many hero elements on a page
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.

3 participants