Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat(common): automatically use sizes auto in NgOptimizedImage #57479

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

Closed
wants to merge 1 commit into from

Conversation

atcastle
Copy link
Contributor

@atcastle atcastle commented Aug 21, 2024

This PR updates NgOptimizedImage so that the 'sizes' prop is prepended with "auto" when the following conditions are met:

  1. The image is responsive (because the user has supplied a sizes value or has used the NgSrcset attribute)
  2. The image is lazy loaded (which will be any time the user has not used the priority attribute or supplied loading="eager"

sizes="auto" is fairly new feature, supported in Chromium and Edge, which uses the actual CSS size of lazy-loaded images to select an image from the srcset, rather than relying on the values manually provided by the user. It will always be at least as accurate as the user's sizes value, and will often be more accurate. In cases where the user has erroneously fallen back to sizes="100vw", using sizes="auto" could reduce image download by 50% or more.

On browsers which do not support sizes="auto", it is simply ignored, and srcset selection behavior will be unchanged.

When browser adoption for sizes="auto" increases, the behavior of NgOptimizedImage could be changed to rely on sizes="auto" completely for lazy loaded images, without requiring the user to provide sizes at all. However, give the current partial state of adoption, I think this smaller change is the best option--it improves loading performance in some cases, and never makes it worse.

CC: @AndrewKushnir @kara

@pullapprove pullapprove bot requested a review from thePunderWoman August 21, 2024 23:06
@angular-robot angular-robot bot added detected: feature PR contains a feature commit area: common Issues related to APIs in the @angular/common package labels Aug 21, 2024
@ngbot ngbot bot added this to the Backlog milestone Aug 21, 2024
@AndrewKushnir AndrewKushnir added target: minor This PR is targeted for the next minor release action: review The PR is still awaiting reviews from at least one requested reviewer labels Aug 21, 2024
@AndrewKushnir AndrewKushnir removed the request for review from thePunderWoman August 21, 2024 23:26
Prepend 'auto' to value of the `sizes` prop generated by NgOptimizedImage, when image has a responsive srcset and is lazy-loaded.
Copy link
Contributor

@kara kara left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@kara kara added action: presubmit The PR is in need of a google3 presubmit merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Aug 26, 2024
@AndrewKushnir
Copy link
Contributor

Presubmit.

@AndrewKushnir AndrewKushnir added action: merge The PR is ready for merge by the caretaker and removed action: presubmit The PR is in need of a google3 presubmit labels Aug 27, 2024
@AndrewKushnir
Copy link
Contributor

Caretaker note: presubmit is "green" for this PR, the PR is ready for merge.

@alxhub
Copy link
Member

alxhub commented Aug 27, 2024

This PR was merged into the repository by commit 50f08e6.

The changes were merged into the following branches: main

@alxhub alxhub closed this in 50f08e6 Aug 27, 2024
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker area: common Issues related to APIs in the @angular/common package detected: feature PR contains a feature commit merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants