feat(common): add <link> preload tag on server for priority img#47343
feat(common): add <link> preload tag on server for priority img#47343yharaskrik wants to merge 2 commits intoangular:mainfrom
Conversation
593690d to
e0dfadb
Compare
kara
left a comment
There was a problem hiding this comment.
Thanks for the PR! In general, looks good, but needs a test
packages/common/src/directives/ng_optimized_image/ng_optimized_image.ts
Outdated
Show resolved
Hide resolved
packages/common/src/directives/ng_optimized_image/ng_optimized_image.ts
Outdated
Show resolved
Hide resolved
c717fb8 to
2951b45
Compare
packages/common/src/directives/ng_optimized_image/ng_optimized_image.ts
Outdated
Show resolved
Hide resolved
|
@yharaskrik thanks again for working on this feature! We think it'd bring a lot of value in SSR scenarios and we'd like to merge it before the v15 feature freeze date (Oct 12). Please let us know if you may have a chance to look into this and/or you want us to help with some of the changes. If I understand correctly, the remaining items are:
After that we can start the final code-review round, perform the necessary tests in Google's codebase and we should be ready for merge. Thank you. |
|
@AndrewKushnir sounds good! Just replied to Kara for some additional clarification as unless I'm missing something I don't see what she is referring to currently in the code, but maybe I'm missing it! I'll make the config related changes tonight hopefully! |
|
@yharaskrik just wanted to ask if you want us to help somehow with the changes from this PR and/or there are open questions we can help address. |
Hey @AndrewKushnir! Sorry things got crazy this last week, I do have a question about @kara comment that I have been meaning to post, Kara you are totally right that is is preloading the wrong one, but I am not following how I am going to figure out what one to preload. We can get the Let me know what I am missing here thanks you two! |
|
@yharaskrik Oh, the whole point of There's more context in the docs here: |
OH those attributes are on the |
fce5fb8 to
ea32daa
Compare
Is that better than just doing this?: Not sure if the params to create renderer are important? (especially cause we are only adding to |
4b9411c to
9f089fc
Compare
packages/common/src/directives/ng_optimized_image/preload-link-creator.ts
Outdated
Show resolved
Hide resolved
9f089fc to
8bf432e
Compare
|
@yharaskrik the PR #47547 that adds |
8bf432e to
b3576a8
Compare
There ya go sir. |
b3576a8 to
d0edffd
Compare
|
There seems to be some seemingly unrelated test failures now and I cannot for the life of me track them down. It's like there are some leaks between tests as some tests are getting entirely different values than are configured on the Whereas the whereas the next test down is configured like so Any help would be appreciated! |
@yharaskrik thanks for highlighting this issue, I will look into this now and let you know. |
This commit adds a logic that generates preload tags for priority images, when rendering happens on the server (e.g. Angular Universal).
d0edffd to
2969b99
Compare
|
@yharaskrik it looks like there was an issue with the rebase and an extra condition that was added in the PR #47547 got inserted in a different place. I've added a fixup commit to resolve this: 2969b99 |
atcastle
left a comment
There was a problem hiding this comment.
This looks good to me--I checked where the merge conflicts were resolved with the automatic srcset PR and it seems like it'll work fine.
| }); | ||
|
|
||
| const template = | ||
| `<img ngSrc="${src}" width="150" height="50" priority sizes="10vw" ngSrcset="100w">`; |
There was a problem hiding this comment.
Let's also include a test with no ngSrcset to make sure that the link element is picking up the automatically-generated srcset
There was a problem hiding this comment.
Ok I'll try and get to that today
There was a problem hiding this comment.
@yharaskrik let's address this feedback in a followup PR (adding changes to this PR would reset approvals).
|
Presubmit #2 (internal link). |
AndrewKushnir
left a comment
There was a problem hiding this comment.
Reviewed-for: public-api
|
@yharaskrik FYI, the current state of this PR is "ready for merge", I'm adding it to the merge queue. There is a feedback from @atcastle (see #47343 (comment)), which we can handle in a followup PR. Please do not push any additional changes for now (it'd reset all approvals). I will let you know once this PR is merged. |
|
Merge-assistance (cc @jessicajaniuk): this PR is ready for merge. Pawel's feedback has been addressed, but since he is OOO, we can't change the status. |
Ok sounds good! |
|
This PR was merged into the repository by commit 75e6297. |
|
@yharaskrik just wanted to say thank you once again for all your work on this PR 👍 |
Thank you for all the help and guidance! Hope I can contribute again soon! I'd be curious what the future plans of the image directive is as I think that's a great step forward! (I'm in the angular slack as well) |
|
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. |


While in Angular Universal, for images that are priority add a preload tag to the to ensure the image is preloaded before it is rendered. This resolves a warning when running Lighthouse.
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Currently when using the
NgOptimizedImagedirective on<img>tags with thepriorityattribute (as suggested in the docs), Lighthouse will show a warning about preloading some assets to improve LCP metrics.More here: https://web.dev/preload-critical-assets/#effects-of-preloading-on-core-web-vitals
Issue Number: N/A
What is the new behavior?
While rendering a page in Angular Universal if an image is going to be loaded with
priority="true"then add a preload tag to the so that when the browsers renders the static HTML (rendered from the server) there are preload links for the browser to start loading the LCP images ahead of time and thus satisfying Lighthouse.Does this PR introduce a breaking change?
Other information
Investigation numbers here: https://twitter.com/JayCooperBell/status/1566231614849331200