Skip to content

Instantly share code, notes, and snippets.

@ashaw
Created March 28, 2011 21:22
Show Gist options
  • Save ashaw/891314 to your computer and use it in GitHub Desktop.
Save ashaw/891314 to your computer and use it in GitHub Desktop.
def minify_css(css)
# take out new lines
css.gsub!(/\n/,'')
# take out spaces between selectors and rule blocks
css.gsub!(/([\.a-zA-Z_\-\#]+?)\s*\{\s*([^\{\}\s])?/,'\1{\2')
# take out spaces between rule block endings and selectors
css.gsub!(/\}\s*([\.a-zA-Z_\-\#]+?)/,'}\1')
# take out spaces between rules
css.gsub!(/(:|;)(\s+)?([\.a-zA-Z_0-9]+)?/,'\1\3')
# take out comments
css.gsub!(/(\/\*.*\*\/)/,' ')
css
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment