find unused css declarations

ever tried to find unused declarations in one file or a bunch of 100 kB of CSS files? it’s a work your worst enemies should do. especially because these CSS files are not written for human minds anyway. they are written to be interpreted by computers. so ⅰ was surprised that there seems no standard program to filter out declarations of CSS which aren’t used. but finally ⅰ found a program in form of a ruby rakefile which does the dirty job: deadweight. as ⅰ usually don’t work with ruby, there were some stumbling blocks to get this working. assuming you have an ruby stack on your GNU/Linux or MacOS Ⅹ workstation already installed.
add the github ruby gems to your library:
gem sources -a http://gems.github.com
download aanand’s code:
sudo gem install aanand-deadweight
(normally it will be installed to/usr/local/)
save one of the examples from the deadweight-website as mywebsite.rb, edit dw.root and dw.stylesheets as you need it. try to run the script as
ruby mywebsite.rb
you may get error messages back like
/usr/lib/ruby/1.8/deadweight.rb:1:in `require': no such file to load -- css_parser (LoadError)
in this case you need to install css_parser with
gem install css_parser
and/or export the rubygems with:
export RUBYOPT=rubygems
now you may find out that the example is not really a ruby script but a ruby makefile called rakefile. so we don’t start it with ruby but with:
rake --rakefile mywebsite.rb deadweight
looks silly for a shell scripter and perl hacker but it works!
thanks to aanand!

Discussion Area - Leave a Comment