Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
minifies css rules (string). naive approach (doesn't interpret anything)
var minifyCss = function(s) {
s = s.replace('\n', ''); // remove newlines
s = s.replace(/\s+/g, ' '); // several whitespace to 1 spacebar
s = s.replace(/\s*([:;,{}])\s*/g, '$1'); // strips whitespace around :;,{} characters
s = s.replace(/\/\*(.|[\r\n])*?\*\//g, ''); // uses non-greedy matching *? to remove comments
return s;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment