class Rainpress


This is the main class of Rainpress, create an instance of it to compress your CSS-styles.


Uwe L. Korn <>


  • :comments - if set to false, comments will not be removed

  • :newlines - if set to false, newlines will not be removed

  • :spaces - if set to false, spaces will not be removed

  • :colors - if set to false, colors will not be modified

  • :misc - if set to false, miscellaneous compression parts will be skipped

Public Class Methods

compress(style, options = {})

Quick-compress the styles. This eliminates the need to create an instance of the class

new(style, opts = {})

Public Instance Methods


Run the compressions and return the newly compressed text


Do miscellaneous compression methods on the style.


Remove all comments out of the CSS-Document

Only /* text */ comments are supported. Attention: If you are doing css hacks for IE using the comment tricks, they will be removed using this function. Please consider for IE css style corrections the usage of conditionals comments in your (X)HTML document.


Remove all newline characters

We take care of Windows(rn), Unix(n) and Mac(r) newlines.


Remove unneeded spaces

  1. Turn mutiple spaces into a single

  2. Remove spaces around ;:{},

  3. Remove tabs


Replace color values with their shorter equivalent

  1. Turn rgb(,,)-colors into -values

  2. Shorten #AABBCC down to #ABC

  3. Replace names with their shorter hex-equivalent

    • white -> fff

    • black -> #000

  4. Replace -values with their shorter name

    • f00 -> red