Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LESS/SASS CSS opposite from minification/optimizations?

Tags:

css

sass

less

I wonder can I say that LESS/SASS CSS "pre-processors(I think they are called?)" is the opposite from optimizations like minification? I wonder if there will be any noticeable performance impact? or do you think easy of development is more important?

I ask this because what LESS CSS generates is something like

body #div1 #div2 p
body #div1 #div2 p a:link, body #div1 #div2 p a:visited
...

and I think it can really bloat up my CSS quite a bit. as you can see, such specificity is not required and it makes reading CSS hard (at least what I see in firebug).

like image 761
Jiew Meng Avatar asked Aug 19 '10 04:08

Jiew Meng


1 Answers

In Sass you can control 'specificity bloat' by understanding how nesting works. You don't have to do any nesting at all if you don't want - it's something you can control.

Using the new @extend directive, you can actually reduce redundancy in your CSS by applying the priciples of OOCSS and can thus improve performance. Here's a good article to get you started with @extend. And a few more OOCSS resources:

  • http://www.stubbornella.org/content/category/general/geek/css/oocss-css-geek-general/
  • http://wiki.github.com/stubbornella/oocss/faq
  • http://oocss.org/

The great advantage of @extend in Sass is that it takes the manual effort involved in applying OOCSS and makes it wonderfully painless and easy.

Finally, as Andrea pointed out, Sass has a variety of options for minifying CSS (see the :compressed style), so overall you've actually got a pretty potent toolkit for not only improving your performance as a developer, but also improving the performance of your CSS. For an example of this in action, see how Chris Eppstein, author of Compass and core contributor of Sass, refactors the Digg stylesheet down from 125 lines of code to 85 lines of code (a 32% reduction).

like image 176
Charles Roper Avatar answered Oct 11 '22 17:10

Charles Roper