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

fix(common): Add fetchpriority to ngOptimizedImage preloads #48010

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions aio/content/guide/image-directive.md
Expand Up @@ -60,6 +60,7 @@ Marking an image as `priority` applies the following optimizations:

* Sets `fetchpriority=high` (read more about priority hints [here](https://web.dev/priority-hints))
* Sets `loading=eager` (read more about native lazy loading [here](https://web.dev/browser-level-image-lazy-loading))
* Automatically generates a [preload link element](https://developer.mozilla.org/en-US/docs/Web/HTML/Link_types/preload) if [rendering on the server](/guide/universal).

Angular displays a warning during development if the LCP element is an image that does not have the `priority` attribute. A page’s LCP element can vary based on a number of factors - such as the dimensions of a user's screen, so a page may have multiple images that should be marked `priority`. See [CSS for Web Vitals](https://web.dev/css-web-vitals/#images-and-largest-contentful-paint-lcp) for more details.

Expand Down
Expand Up @@ -65,6 +65,7 @@ export class PreloadLinkCreator {
renderer.setAttribute(preload, 'as', 'image');
renderer.setAttribute(preload, 'href', src);
renderer.setAttribute(preload, 'rel', 'preload');
renderer.setAttribute(preload, 'fetchpriority', 'high');

if (sizes) {
renderer.setAttribute(preload, 'imageSizes', sizes);
Expand Down
1 change: 1 addition & 0 deletions packages/common/test/directives/ng_optimized_image_spec.ts
Expand Up @@ -68,6 +68,7 @@ describe('Image directive', () => {
expect(preloadLink!.getAttribute('as')).toEqual('image');
expect(preloadLink!.getAttribute('imagesizes')).toEqual('10vw');
expect(preloadLink!.getAttribute('imagesrcset')).toEqual(`${rewrittenSrc}?width=100 100w`);
expect(preloadLink!.getAttribute('fetchpriority')).toEqual('high');

preloadLink!.remove();
});
Expand Down