Hacker News new | past | comments | ask | show | jobs | submit login

I find problems with both the author's methodology and hypothesis.

Counting unique declarations doesn't really tell me anything. CSS isn't simply a declarative language. CSS rules are ordered. Sometimes (and oftentimes within webapps) you need to repeat a declaration because you're using it to overwrite an earlier declaration but only when the second selector is valid. For example, it's very common to have lots of `display` declarations that turn on or off elements by overwriting earlier rules. Because of this, you're going to have lots of "repeat" declarations, but they're not repeated in their location within the order. With complex pages, you're going to wind up twisting yourself in knots trying to keep everything logically ordered if you also want to minimize declarations.

Additionally, from my naive understanding of browser engines, the performance cost of multiple rules applying to an element is greater than the cost of multiple declarations within a rule. Why minimize them?

But my largest concern is the mental overhead of trying to simplify rules in code. Co-locating declarations affecting a logical unit is extremely helpful. The tool we have to accomplish this is called a selector. Minimizing declarations increases selector count, which kind of defeats their purpose. Pre-processors can't solve this for you either, due to CSS rules being ordered. If all you're building is a static page then, sure, I can see minimizing declarations being some kind of goal. But CSS gets used for a lot more than static pages.

As other commenters have noted, if the author's concern is overly-large CSS files, run-length encoding alleviates a lot of that, at least if the declarations are in the same file (a reason to not use http2 as a silver bullet and use concatenation instead, if that's a concern).

EDITS: Added a couple sentences.




I agree completely. This just seems like this reordering/grouping of properties makes the css a nightmare to manage and moved scatters related properties all over the stylesheets. It's would be like grouping the same coloured/shaped parts of a car together because they are the same colour and shape, and not grouping them by what they are - it might reduce the number of times you need to write the word red, but when you need to update at how a part looks on the car then it would be a mess!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: