tachyons-css / tachyons-styled-react

Tachyons implemented with emotion and styled-system. Sits on create-react-app.
https://tachyons-styled-react.now.sh
200 stars 17 forks source link

Unused styles comment #13

Closed dferber90 closed 5 years ago

dferber90 commented 5 years ago

While Tachyons is light-weight by default, using css-in-js will result in increased css performance as you don't send unused styles down the wire.

I was wondering about this statement and did a bit of research. When building a page we either only need tachyons.min.css or we need the setup for styled-system, emotion and the theme itself.

So to do a fair comparison we'd have to compare tachyons.min.css at 10.9kB vs the rest at 16.4kB. So in terms of payload we are actually shipping ~6kB more. This comparison is excluding the size of the elements definitions and the theme itself.

Not related to create-react-app, but relevant when used with static prerendering (e.g. with react-snap or in Gatsby): Using css-in-js setup ( styled-system and emotion) enables inlining critical CSS which avoids the flash of unstyled content seen when using plain CSS.

The downside is that the critical CSS is loaded "twice" then: once as the critical inlined CSS and once through the JS bundle (theme etc).

Both solutions are coming in pretty lightweight and a 6kb difference won't matter for most connection speeds. So the most promising aspect to me is that we can enable avoiding the flash-of-unstyled-content with this css-in-js setup.

I did not confirm the theories stated above but wanted to share my ramblings. I'll close this again as I don't want to do anything else besides sharing some thoughts. Thanks for coming to my TED talk.