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

Don't preload hero images #1132

Merged
merged 1 commit into from
Jan 29, 2021
Merged

Don't preload hero images #1132

merged 1 commit into from
Jan 29, 2021

Conversation

sebastianbenz
Copy link
Collaborator

We can't tell whether a hero image is responsive and is loaded depending
on viewport size. The current implementation will always preload hero
images, which means images might be preloaded even if they are not
visible on the page. This PR reverts this behavior and disables
preload generation for hero images.

The only exception is when an image defines a media attribute.

We can't tell whether a hero image is responsive and is loaded depending
on viewport size. The current implementation will always preload hero
images, which means images might be preloaded even if they are not
visible on the page. This PR reverts this behavior and disables
preload generation for hero images.

The only exception is when an image defines a media attribute.
preload.attribs.media = heroImage.media;
if (!heroImage.media) {
// We can only safely preload a hero image if there's a media attribute
// as we can't detect whether it's hidden on certain viewport sizes otherwise.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why? Is it an opt in sort of thing, or does the media attr provide some kind of indication of..something?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is AMP's built in way to define per element media queries. The assumption is that if you use this, you won't define additional media queries in CSS. This could still lead to false positives, but I suspect that this is seldom the case.

Copy link
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

@sebastianbenz sebastianbenz merged commit b7062d8 into main Jan 29, 2021
@sebastianbenz sebastianbenz deleted the image-preload branch January 29, 2021 15:17
sebastianbenz added a commit that referenced this pull request Jan 29, 2021
This PR makes image optimization more flexible by making it possible to
configure hero image count and blurry image placeholder generation on a
per page basis.

This PR also deprecates the preloadHeroImage option in favor of a new
optimizeHeroImages option as preloading has been disabled in most cases (see
#1132).
sebastianbenz added a commit that referenced this pull request Jan 29, 2021
This PR makes image optimization more flexible by making it possible to
configure hero image count and blurry image placeholder generation on a
per page basis.

This PR also deprecates the preloadHeroImage option in favor of a new
optimizeHeroImages option as preloading has been disabled in most cases (see
#1132).
sebastianbenz added a commit that referenced this pull request Jan 29, 2021
This PR makes image optimization more flexible by making it possible to
configure hero image count and blurry image placeholder generation on a
per page basis.

This PR also deprecates the preloadHeroImage option in favor of a new
optimizeHeroImages option as preloading has been disabled in most cases (see
#1132).
sebastianbenz added a commit that referenced this pull request Feb 1, 2021
This PR makes image optimization more flexible by making it possible to
configure hero image count and blurry image placeholder generation on a
per page basis.

This PR also deprecates the preloadHeroImage option in favor of a new
optimizeHeroImages option as preloading has been disabled in most cases (see
#1132).
sebastianbenz added a commit that referenced this pull request Feb 1, 2021
* More flexible hero images and blurry placeholders

This PR makes image optimization more flexible by making it possible to
configure hero image count and blurry image placeholder generation on a
per page basis.

This PR also deprecates the preloadHeroImage option in favor of a new
optimizeHeroImages option as preloading has been disabled in most cases (see
#1132).

* improve wording

* log deprecated option
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.

2 participants