Skip to content

Commit 567c2f6

Browse files
JeanMechealxhub
authored andcommitted
docs: add NG0913 error doc (angular#56352)
File copied from AIO. fixes angular#56351 PR Close angular#56352
1 parent 33d1aa6 commit 567c2f6

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

adev/src/app/sub-navigation-data.ts

+5
Original file line numberDiff line numberDiff line change
@@ -1259,6 +1259,11 @@ const REFERENCE_SUB_NAVIGATION_DATA: NavigationItem[] = [
12591259
path: 'errors/NG0912',
12601260
contentPath: 'reference/errors/NG0912',
12611261
},
1262+
{
1263+
label: 'NG0913: Runtime Performance Warnings',
1264+
path: 'errors/NG0913',
1265+
contentPath: 'reference/errors/NG0913',
1266+
},
12621267
{
12631268
label: 'NG0950: Required input is accessed before a value is set.',
12641269
path: 'errors/NG0950',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Runtime Performance Warnings
2+
3+
### Oversized images
4+
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). 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/).
5+
6+
### Lazy-loaded LCP element
7+
The largest contentful element on a page during load is considered the "LCP Element", which relates to [Largest Contentful Paint](https://web.dev/lcp/), one of the Core Web Vitals. Lazy loading an LCP element will have a strong negative effect on page performance. With this strategy, the browser has to complete layout calculations to determine whether the element is in the viewport before starting the image download. As a result, a warning is triggered when Angular detects that the LCP element has been given the `loading="lazy"` attribute.
8+
9+
@debugging
10+
Use the image URL provided in the console warning to find the `<img>` element in question.
11+
### Ways to fix oversized images
12+
* Use a smaller source image
13+
* Add a [`srcset`](https://web.dev/learn/design/responsive-images/#responsive-images-with-srcset) if multiple sizes are needed for different layouts.
14+
* Switch to use Angular's built-in image directive ([`NgOptimizedImage`](https://angular.io/api/common/NgOptimizedImage)), which generates [srcsets automatically](https://angular.io/guide/image-directive#request-images-at-the-correct-size-with-automatic-srcset).
15+
### Ways to fix lazy-loaded LCP element
16+
17+
* Change the `loading` attribute to a different value such as `"eager"`.
18+
* Switch to use Angular's built-in image directive ([`NgOptimizedImage`](https://angular.io/api/common/NgOptimizedImage)), which allows for easily [prioritizing LCP images](https://angular.io/guide/image-directive#step-4-mark-images-as-priority).
19+
20+
### Disabling Image Performance Warnings
21+
Both warnings can be disabled individually, site-wide, using a provider at the root of your application:
22+
23+
<code-example format="typescript" language="typescript">
24+
providers: [
25+
{
26+
provide: IMAGE_CONFIG,
27+
useValue: {
28+
disableImageSizeWarning: true,
29+
disableImageLazyLoadWarning: true
30+
}
31+
},
32+
],
33+
</code-example>
34+

0 commit comments

Comments
 (0)