Skip to content

Instantly share code, notes, and snippets.

@JosePedroDias
Created March 17, 2014 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JosePedroDias/9599806 to your computer and use it in GitHub Desktop.
Save JosePedroDias/9599806 to your computer and use it in GitHub Desktop.
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