Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Refactoring and removing unused CSS from SASS/LESS files

I am working on a big single page application [backbonejs and rails] which has LESS as the CSS preprocessor and the generated .css files has grown to such an extent that for IE we have to split it into 3 files with http://blesscss.com/

Though there are tools to detect unused css and linting css, I am unable to find a proper solution for refactoring LESS/SASS files directly from uncompiled files instead of a single large generated .css file.

Would like to know what is the best approach doing these tasks?

Thanks in advance !

like image 334
Imran Khan Avatar asked Dec 28 '13 05:12

Imran Khan


People also ask

How do I clean up unused CSS?

If you want to remove unused CSS entirely, you can use a tool such as PurifyCSS to find out how much CSS file size can be reduced. Once you get the CSS code you should eliminate, you have to remove it manually from the page.

Does PostCSS remove unused CSS?

This is a simple to use PostCSS plugin that removes CSS selectors based on your other files.

How do you reduce unused CSS in react?

Open UnCSS and paste the copied HTML code inside the HTML section and also copy the CSS from your stylesheet and paste it under the CSS section and click on UNCSS MY STYLES in it will automatically generate the CSS which is required by removing the unused CSS from the stylesheet.

What is purge CSS?

PurgeCSS removes unused CSS rules from your stylesheets to reduce their size and therefore speed up page-loads. It's very important that you configure this tool correctly, or it will remove CSS rules that you need!


1 Answers

  1. For finding and remove unused CSS use Uncss which has implementation as tasks for Grunt and Gulp
  2. For finding unused variables in your SASS/LESS code- some script like this one.
  3. For debug source files instead one generated css- source maps
  4. To minify your code, use compressed output styles
  5. To automatically add vendor prefixes for browsers in your css use Autoprefixer
  6. Generally- provide Grunt or Gulp build for your css

P.S.: Some of the links are just for SASS- for Less there are similar solutions which are easy to find.

like image 181
Serg Hospodarets Avatar answered Oct 18 '22 21:10

Serg Hospodarets