CSS minification with YUI compressor, but as native Ruby port
CSS Ruby
Switch branches/tags
Nothing to show
Latest commit e6133cc Jan 21, 2016 @matthiassiegel Update README
Failed to load latest commit information.
lib 1.0.2 release Jun 30, 2012
spec 1.0.1 release Jun 30, 2012
.gitignore Initial commit Jun 29, 2012
.travis.yml Travis CI integration Jul 20, 2012
CHANGES.md 1.0.2 release Jun 30, 2012
Gemfile Initial commit Jun 29, 2012
LICENSE.md Initial commit Jun 29, 2012
README.md Update README Jan 21, 2016
cssminify.gemspec Removed unnecessary Bundler dependency Jun 30, 2012


CSSminify Build Status

CSS minification with YUI compressor, but as native Ruby port.

The CSSminify gem provides CSS compression using YUI compressor. Instead of wrapping around the Java or Javascript version of YUI compressor it uses a native Ruby port of the CSS engine. Therefore this gem has no dependencies.

In basic benchmarks the Ruby version performed about as good as the Java jar. It currently passes all CSS test cases included with the YUI compressor Java source code.

Main motivation for the Ruby port and this gem was to reduce dependencies like Java.

PLEASE NOTE: this project is no longer maintained.


Install CSSminify from RubyGems:

gem install cssminify

Or include it in your project's Gemfile:

gem 'cssminify'


require 'cssminify'

CSSminify.compress('/* a comment */ .test { display: block; }')
# => minified CSS

# => minified CSS

# => minified CSS

# Alternatively use instance method...
compressor = CSSminify.new
# => minified CSS

Files or strings are acceptable as input.

You can pass in a second argument to control the maximum output line length (default 5000 characters):

CSSminify.compress(File.read("path/to/styles.css"), 200)

Note: in most cases line length will only be approximated.

Rails asset pipeline

Rails 3.1 integrated Sprockets to provide asset packaging and minimising out of the box. For CSS compression it relies on the yui-compressor gem which requires Java. To use CSSminify instead, edit your config/application.rb file:

config.assets.css_compressor = CSSminify.new


Tested with Ruby 1.9.2, 1.9.3, jruby-19mode, rbx-19mode




CSSminify gem and documentation

Copyright (c) 2012 Matthias Siegel (matthias.siegel@gmail.com) See LICENSE for details.

YUI compressor

See file.