Prevent SSR for amp-img occurring after second paragraph#141
Merged
schlessera merged 5 commits intomainfrom Apr 10, 2021
Merged
Prevent SSR for amp-img occurring after second paragraph#141schlessera merged 5 commits intomainfrom
schlessera merged 5 commits intomainfrom
Conversation
westonruter
reviewed
Apr 9, 2021
Comment on lines
+751
to
+753
| if ($element->hasAttribute(Attribute::DATA_HERO)) { | ||
| return true; | ||
| } |
Member
There was a problem hiding this comment.
Since DetermineHeroImages in the AMP plugin is making educated decisions about what images are heroes in WordPress, I think such images should not get loading=lazy.
Suggested change
| if ($element->hasAttribute(Attribute::DATA_HERO)) { | |
| return true; | |
| } | |
| if ($element->hasAttribute(Attribute::DATA_HERO) || $element->hasAttribute(Attribute::DATA_HERO_CANDIDATE)) { | |
| return true; | |
| } |
Member
There was a problem hiding this comment.
Or maybe not per https://github.com/ampproject/amp-wp/pull/6062/files#r611001630. Alternatively: https://github.com/ampproject/amp-toolbox-php/pull/141/files#r611001917.
4 tasks
westonruter
reviewed
Apr 10, 2021
| // outside the viewport. | ||
| if (! $this->isMarkedAsHeroImage($element)) { | ||
| $imgElement->setAttribute(Attribute::LOADING, 'lazy'); | ||
| } |
Member
There was a problem hiding this comment.
Maybe there should be an else case here to see if there is a noscript > img maybe this should copy the loading attribute from that image if it is set.
Collaborator
Author
There was a problem hiding this comment.
I'm creating a separate issue for this, as I want the tests to be fixed again.
See #147
236464f to
07c311e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR skips hero image prerendering after paragraph 2 and adds lazy-loading to hero images that were detected without being explicitly marked.
See ampproject/amp-toolbox#1196
Depends on ampproject/amp-toolbox#1198