Hacker News new | ask | show | jobs
by stefanchrobot 3016 days ago
I'd add one thing: avoid multiple classes on a single element; use mixins to avoid duplication. I tend to do so even for classes that have some toggle state, i.e. .some-class-active.
1 comments

does this have a performance benefit or are you recommending it for the code clarity?
It'll increase your parse and network transfer time (gzip might help there though) in exchange for reduced selector matching and style computation time. How much that matters probably depends on your content, how big the document is, how much CSS you have and how many classes you're using.

If you're talking about the difference of:

.a { ... } .b { ... } .ab { ... }

<div class="a b"></div> <div class="ab"></div>

It's probably not going to matter a lot. It's two map lookups vs one, and some associated overhead. Probably better to optimize elsewhere. :)