Created
August 27, 2011 19:26
-
-
Save rafbm/1175769 to your computer and use it in GitHub Desktop.
CSS compressor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var compressCSS = function(css) { | |
return css.trim() | |
.replace(/\s*([{}:;,>+~])\s*/g, '$1') // whitespace | |
.replace(/;}/g, '}') // trailing semicolons | |
.replace(/#(\w)\1(\w)\2(\w)\3\b/g, '#$1$2$3') // hex colors | |
.replace(/(\[[^=]+=)("|')([^"'\s]+)(\2)(\])/g, '$1$3$5') // useless attribute selector quotes | |
.replace(/\(('|")([^"'\s]+)(\1)\)/g, '($2)') // useless function quotes | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment