-
Notifications
You must be signed in to change notification settings - Fork 12k
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
feat(@angular/ssr): add modulepreload
for lazy-loaded routes
#28919
base: main
Are you sure you want to change the base?
Conversation
95f2b19
to
9b4c01a
Compare
913f62e
to
1eb3c20
Compare
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 putting this together! I left some initial thoughts.
I think my biggest concern is that I'm not sure how comfortable I am .toString()
-ing a function and parsing out the dynamic import()
statement at runtime in a production server. It's hard to explain concrete concerns, but it feels off to have a program inspect its own source code and alter behavior as a result.
I'm curious to explore if there is an opportunity with a compiler transform to create a similar result without having to toString
an arbitrary function? Let's chat about this and see what our options are. @AndrewKushnir might also be interested in this.
return html; | ||
} | ||
|
||
const bodyCloseIdx = html.lastIndexOf('</body>'); |
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.
Consider: Users can do pretty weird things in the HTML like:
<!DOCTYPE html>
<html>
<body>
<!-- ... -->
</body>
<script>
document.documentElement.outerHTML.replace('</body>', '</body><script src="..."></script>');
</script>
</html>
Technically the last </body>
would be in the JS, not the HTML.
It's a pretty extreme scenario, so I don't know that we really need to be too concerned about it. The "correct" solution is likely using a real HTML parser, but that might be worth it for this kind of edge case.
I mainly just wanted to point out this potential issue, up to you if it's worth solving. If we do choose to leave this, I would recommend at least having a comment which calls out that behavior.
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.
This is quite an extreme edge case, that I feel that we should not worry about right now.
tests/legacy-cli/e2e/tests/build/server-rendering/server-routes-preload-links.ts
Show resolved
Hide resolved
tests/legacy-cli/e2e/tests/build/server-rendering/server-routes-preload-links.ts
Show resolved
Hide resolved
This only happens during the build, when building the manifest, on a production server the preloads are already extracted. |
Enhance performance when using SSR by adding `modulepreload` links to lazy-loaded routes. This ensures that the required modules are preloaded in the background, improving the user experience and reducing the time to interactive. Closes angular#26484
1eb3c20
to
4cb8cf5
Compare
Enhance performance when using SSR by adding
modulepreload
links to lazy-loaded routes. This ensures that the required modules are preloaded in the background, improving the user experience and reducing the time to interactive.Closes #26484