npm install -g uncss
Using UnCSS from the Command Line
UnCSSrequiresthefilepathorURLofanHTMLpagethatcontainsalinkedCSS
file;forexample:
uncss http://sitepoint.com/
UnCSSwillparsetheHTMLanditslinkedstylesheets,andprinttheoptimized
CSStostandardoutput.Toredirecttoafile,usetheredirectoperator(>):
uncss http://sitepoint.com/ > optimized.css
YoucanalsopassmultiplefilepathsorURLstothecommandline.CSSwillanalyze
eachfileanddumpoptimizedCSSthatcontainsrulesaffectingoneormorepages:
uncss index.html article-1.html article-2.html > optimized.css
For a full list of commands―and an example of how to use UnCSS with a Node.js
script―consult the UnCSSdocs.^8
Consider a Task Runner
Thisprobablysoundslikealotofextratimeandstepstoaddtoyourworkflow,but
youshouldconsiderataskrunnersuchGrunt^9 orbuildsystemsuchasGulp.^10 It’s
whereautomationcanhelpquiteabit.
Gruntisthemoreestablishedofthetwotools,sotherearemorepluginsandalarger
community.IhappentobepartialtoGulp’ssyntax.Usewhichevertoolworksbest
foryouandyourcolleagues.
What’sgreataboutGruntandGulpisthatyoucanassembleatoolchainthatwill
automaticallyrunconcatenation,minification,andoptimizationtasksforCSS,
JavaScript,andimagefiles.BecausetheconfigurationandbuildscriptfilesareJSON
(^8) https://github.com/giakki/uncss
(^9) http://gruntjs.com
(^10) http://gulp.js
126 CSS Master