简体   繁体   中英

What is faster, raw CSS or inline styles in ReactJS?

Does the ReactJS virtual DOM make your app faster if you put all CSS as inline style? VS using raw .css files?

http://facebook.github.io/react/tips/inline-styles.html

Also see this ReactJS presentation on CSS in JavaScript: https://speakerdeck.com/vjeux/react-css-in-js

Browsers have put years of efforts into making their CSS stylesheet parsing + rendering engines blazing fast and memory efficient. Inline styles haven't exactly had that same treatment. However the bright side is that it actually doesn't matter much if you're creating normal-sized apps/pages. The difference is miniscule. Inline styles make up for the fact that 100% of the styles are actually used, where CSS stylesheets are often concatenated and almost 90% of the parsed rules are inactive (wasted).

Tip: Improve your performance by avoiding React re-renders. That's where the bottleneck often really is!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM