-
Notifications
You must be signed in to change notification settings - Fork 26.5k
feat(core): add warnings for oversized images and lazy-lcp #51846
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this! Mostly comments about docs and testing
packages/common/src/directives/ng_optimized_image/ng_optimized_image.ts
Outdated
Show resolved
Hide resolved
aio/content/errors/NG913.md
Outdated
After an application is loaded, Angular checks included `<img>` elements for performance-harming misconfiguration. This warning can be triggered two ways: | ||
|
||
### Oversized images | ||
When images are loaded, the **intrinsic size** of the downloaded file is checked against the **rendered size** of the image on the page. If the downloaded image is much larger (more than 1200px too large in either dimension), this warning is triggered. Downloading oversized images can slow down page loading and have a negative effect on [Core Web Vitals](https://web.dev/vitals/). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: may want to add a note about the pixel density being part of it to prevent confusion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point--this actually made me go back and change something else. In the existing oversized image check, we were using a fixed value of 2 to align with the top bounds of the generated srcsets. For non-NgOptimizedImage
images, that's a little confusing, so I updated the logic to just multiply by window.devicePixelRatio
directly. I changed the error page to read:
When images are loaded, the **intrinsic size** of the downloaded file is checked against the actual size of the image on the page. The actual size is calculated using the **rendered size** of the image with CSS applied, multiplied by the [pixel device ratio](https://web.dev/codelab-density-descriptors/#pixel-density).
d3b9e36
to
6e67dc5
Compare
TGP. |
6e67dc5
to
6614353
Compare
// Wait to avoid race conditions where LCP image triggers | ||
// load event before it's recorded by the performance observer | ||
const waitToScan = () => { | ||
setTimeout(this.scanImages.bind(this), 200); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we keep 200, let's may be move it to a const outside of the class and add a note on what it is and why it's 200.
6614353
to
d9d316d
Compare
82b47c7
to
f5c3017
Compare
TGP. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
reviewed-for: fw-core, fw-common, public-api
Add warnings for two image-related performance problems that apply beyond just apps using NgOptimizedImage.
f5c3017
to
6c10f7b
Compare
Caretaker note: TGP is green, this PR is ready for merge. |
This PR was merged into the repository by commit 048f400. |
console.warn(formatRuntimeError( | ||
RuntimeErrorCode.IMAGE_PERFORMANCE_WARNING, | ||
`An image with src ${src} has intrinsic file dimensions much larger than its ` + | ||
`rendered size. This can ` + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this sentence is still trailing off. Fix in a follow-up?
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
…1846) Add warnings for two image-related performance problems that apply beyond just apps using NgOptimizedImage. PR Close angular#51846
This PR adds two new warnings related to image performance to Angular. These warnings are based on existing warning in the NgOptimizedImage directive, but apply to all images, as opposed to just those generated with NgOptimizedImage. The rationale for this is that both of the image performance issues captured by these warnings apply equally to images that don't use the optimized image directive. By surfacing them as warnings, we can help improve Angular loading performance and Core Web Vitals.
The two warnings are:
loading="lazy'
. This can have a strong negative impact on LCP.In both cases, the scanner runs once, on the page
load
event.CC: @AndrewKushnir @kara @dgp1130