-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Can CSS be inlined in the server-rendered pages ? #962
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
Comments
Sapper used rollup-plugin-css-chunks to chunk the CSS files in the same way that the JS files were chunked. Vite is most compatible with Rollup plugins, so potentially you could include that in your build. If that doesn't work, you'd have to put in a feature request over in that repo if you'd like to see that behavior added to Vite |
Inlining critical CSS is a huge win for perceived performance, even when loading assets through HTTP/2. I'd say this is a crucial feature on the road to SvelteKit's production-ready status. Worth mentioning that it's needed both for SSR and static pages. |
Sadly didn't work. I tried to disable vite css splitting, but it doesn't seem to respect my config settings. |
I've successfully mitigated the issue by using HTTP/2 Server Push, depending on your backend, you might wanna look into that |
Interesting to note, CSS is inlined when using dev server, but not during build (adapter-static in my case) |
i use postcss config in sveltekit starter but not work in build project |
This comment has been minimized.
This comment has been minimized.
As of the most recent version, you can inline stylesheets smaller than a certain size with the // svelte.config.js
export default {
kit: {
// inline all stylesheets smaller than 1kb
inlineStyleThreshold: 1024
}
}; |
thx @Rich-Harris ! CSS is inlined, but is it normal that in the HTML still appears : <link disabled rel="stylesheet" href="/_app/assets/index-f3af5aa6.css"> Chrome is loading this CSS file, and it contains CSS that has been inlined |
This is great, @Rich-Harris! 🎉 Does it matter where the source CSS file exists? Does it matter how or where the CSS file is imported? Does the use of an adapter (I'm using I'm setting My endgoal is to inline both the JS and CSS, I found this CSS option first so figured I'd start there. Thank you! I've enjoyed using SvelteKit and Svelte so much thus far! 😄 |
Same here! |
Im afraid i have the same issue. With With
Im using static adapter so it shouldnt matter, but i did the test to see if it will make a difference. And it did, just not in the file that i was expecting to.
|
@pavelloz I can confirm with
For a site that uses adapter static and has a high value for
Don't mind the fact that other adapters are installed, they are not used in the [email protected] /shared/httpd/daiki
├── @sveltejs/[email protected]
├── @sveltejs/[email protected]
├── @sveltejs/[email protected]
├── @sveltejs/[email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected] However.. given https://www.filamentgroup.com/lab/load-css-simpler/ I like to change the output of the <link rel="stylesheet" href="/_app/assets/pages/__layout.svelte-01120fe0.css" disabled media="(max-width: 0)"> to <link rel="stylesheet" href="/_app/assets/pages/__layout.svelte-01120fe0.css" media="print" onload="this.media='all'">
Could this be added as a option to the static adapter perhaps ? |
inlineStyleThreshold doesn't work for me either (using adapter-static). There may be a regression if it was working 7 months ago when @robots4life made the commit that worked for him. I should note that I'm using PostCSS: svelte.config.js |
Thank you for reopening @benmccann. I did some exploration last night and noticed that the |
Could someone provide a minimum reproducible so we can look into it? I did set |
The styles inside the |
That's strange, I don't see this behavior (using Chrome); according to the spec a disabled link tag should be neither downloaded nor executed. A reproducible would really help. |
Thanks, closing in favor of that issue. |
The inline styles being loaded seems to have been a bug in Vite. It fails with 3.1.x, but works with 3.2.x. Updating to the latest version of Vite fixes the bug. |
Currently, HTML is rendered in the response by the server, but the CSS is linked through attributes, thus delaying proper page rendering until the stylesheet request is done.
Is it possible to inline CSS (or at least the 'start' stylesheet) like Next.JS does? Or is it planned?
The text was updated successfully, but these errors were encountered: