I came across a ReactJS Boilerplate which had good reps and is community driven. Styling section emphasized more on styled component CSS but never stopped from switching to conventional CSS styling methodologies. Although this pulled my interests what makes the Styled-Component CSS stand out and why need to adopt it.
My Understanding of Styled component CSS:
- Component Driven idealogy. Your CSS also is now a component. - This is pretty cool!
- Load what you need and when you needed, kinda lazy CSS
- Theme provider, skins, modularity and dynamic - This can be achieved by other libs too
- Server side construction of your component DOM and its style.
My questions are:
Browsers are evolved to parse CSS separately from Javascript parsing, why are we trying to deviate from this and fit all in Javascript?
Styled-component CSS ships its javascript library to the client end, which actually parses styles at the runtime and put inside
<style />
tag when each component loads on demand. This means extra load and logic eventually contributing to execution cycles on browser. Why need this?(By the above question i mean for every component loaded, corresponding CSS is computed, created and inserted in head via
style
tag / Multiple style tags - Re-inventing CSS interpreters)Does continuous computed style text banging via
<style />
in the head tag cause browser reflow/repaint ?What are the performance advantages i get from this?
With add-on libraries / options like Post-CSS & SCSS classname hashing for dynamic classnames which pretty much solves the problem that everyone states. Why SC still ?
Community, please clear the air for me or correct me if i am wrong.
Some good articles that talks about repaint or DOM re-flow how it is performance expensive for browser when CSS styles are modified.
- https://developers.google.com/speed/articles/reflow
- http://www.stubbornella.org/content/2009/03/27/reflows-repaints-css-performance-making-your-javascript-slow/
- https://www.sitepoint.com/10-ways-minimize-reflows-improve-performance/
- https://www.phpied.com/rendering-repaint-reflowrelayout-restyle/
- https://developer.mozilla.org/en-US/docs/Web/API/CSS_Object_Model/Using_dynamic_styling_information