styles.css not included inline in server render
See original GitHub issueI’m submitting a …
- [ ] bug report <!-- Please search GitHub for a similar issue or PR before submitting -->
- [ x] feature request
- [ ] Support request => Please do not submit support request here, instead see https://github.com/angular/universal/blob/master/CONTRIBUTING.md#question
What modules are related to this Issue?
- [ ] aspnetcore-engine
- [ ] common
- [ x] express-engine
- [ ] hapi-engine
- [ ] module-map-ngfactory-loader
Current behavior?
The CSS declared in styles.css is included in the client bundle, but it is not inlined into the server bundle the way component styles are.
Expected behavior?
Any CSS in the styles.css should be (optionally?) inlined in the server rendered html and transitioned out when the client loads, the way other component CSS does.
Minimal reproduction with instructions
- Clone this repo
- Add any CSS to styles.css that should apply anywhere. Eg. body { color: pink; }
- Open any server rendered route and view the html that is generated
- Note that the CSS rule you added does not appear inlined in the HTML, it only appears once the client bundle is loaded.
Environment:
@nguniversal versions
- aspnetcore-engine:
- common:
- express-engine:
- hapi-engine:
- module-map-ngfactory-loader:
<!--
Output from: `ng --version`.
If nothing, output from: `node --version` and `npm --version`.
Windows (7/8/10). Linux (incl. distribution). macOS (El Capitan? Sierra?)
-->
Other information (optional)
My application has a lot of base styles defined in styles.css and it looks really bad before the transition to the client application when these styles are not available in the server view.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:36
- Comments:30 (2 by maintainers)
Top Results From Across the Web
Improve site performance by inlining your CSS - LogRocket Blog
Once you understand how CSS can impact your site performance, you can then look for opportunities to inline your CSS — the right...
Read more >Vue.js server side rendering stop using inline CSS
I am using vue-style-loader in my server side rendering process. It works well, however it renders all the CSS information inline in tag....
Read more >How To Render CSS on React App Servers | DigitalOcean
This pattern encourages style and component composition as well as reuse. However, inline styles does not provide you with a way to handle...
Read more >Dynamically Inlining Critical CSS with Server-side JavaScript
To solve this problem, PageSpeed recommends adding inline CSS to the HTML document. This doesn't mean we want to embed the entire stylesheet...
Read more >Use Custom Styles When the Component Is Rendered in an ...
Components rendered in an inline frame don't have direct access to the design.css file. Instead there is an additional step to get the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I ran into the same issue but found a different workaround.
Forcing Angular to extract the global styles into their own files and loading them using
<link rel="stylesheet">
correctly loads them in both cases, with and without SSR.Set
extractCss
totrue
inbuild/options
inangular.json
.Is there any documentation for
extractCss
?@vikerman We have the exact same problem as the ‘original problem’. The problem is that the
styles
are not ‘loaded’ by the SSR applicationIn our case:
And in FF this sometimes results in a flash. I never noticed this (I don’t really use FF) and I always thought this was a limitation by Angular Universal. But when digging deeper I found out that it’s indeed the global styles that aren’t loaded.
I can share our production url:
https://www.intigriti.com/companies´
where you clearly see this when checking the raw html returned by SSR. (Lot of Times New Roman, non styles navbar, … -> All defined in our global styles)
Is there a recommend workaround?
EDIT: The workaround above works 😉 A played a bit around and now have a balanced ‘index.html’ (not all styling but most of it that’s important on that page)
Sincerely, Brecht And thanks in advance!