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

Option to emit <link>s instead of <style>s in SSR #2851

Open
nolanlawson opened this issue May 24, 2022 · 2 comments
Open

Option to emit <link>s instead of <style>s in SSR #2851

nolanlawson opened this issue May 24, 2022 · 2 comments
Labels

Comments

@nolanlawson
Copy link
Collaborator

nolanlawson commented May 24, 2022

Right now we render inline <style> in components when we do SSR:

<my-component>
  #shadow-root
    <style>div { color: green; }</style>
    <div>Hello</div>
</my-component>

For components that use shared styles or that are repeated many times, this can lead to a lot of duplicated <style>s in the DOM. Browsers are pretty smart about optimizing this, and compression will remove duplication, but it's still a bit sub-optimal. Ideally we should have a mode to emit <link rel=stylesheet>s instead of <style>s. (Or just make <link>s the default.)

@uip-robot-zz
Copy link

This issue has been linked to a new work item: W-11195728

@nolanlawson
Copy link
Collaborator Author

nolanlawson commented Apr 11, 2024

I've thought about this a bit more. Right now there are a few reasons not to do this optimization:

However, we do have some internal evidence that separate <link rel=stylesheet>s may be more performant than inlined <style>s. These tests aren't conclusive, so it would be good to continue experimenting.

If we do implement this, it would be nice to do it in a bundler-agnostic way, similar to how Svelte/Vue allow their stylesheets to be hoisted out of components by Webpack/Rollup/etc. which is responsible for handling the actual *.css files and <link rel=stylesheet>s.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants