Class CSSCompressor

java.lang.Object
com.iizix.js.build.compressors.CSSCompressor

public final class CSSCompressor extends Object
Strips comments and whitespace from CSS input.

IIZI's in-process CSS minifier, used through com.iizix.js.build.Compressor or directly through compress(String) and compress(String, String). It is safe rather than maximal: it never reorders, merges or drops a declaration that means something, and it leaves the value of a custom property as its author wrote it.

Author:
paulh, Barry van Oudtshoorn, Christopher Mindus
  • Constructor Details

    • CSSCompressor

      public CSSCompressor()
      Creates a CSSCompressor, which can minify any number of stylesheets.
  • Method Details

    • compress

      public static String compress(String css) throws IOException
      Minifies a stylesheet.
      Parameters:
      css - The stylesheet.
      Returns:
      The minified stylesheet.
      Throws:
      IOException - If the stylesheet is null or cannot be minified: the message says what is wrong and where (line and column).
    • compress

      public static String compress(String css, String sourceName) throws IOException
      Minifies a stylesheet and names its source in a failure.
      Parameters:
      css - The stylesheet.
      sourceName - The name of the stylesheet's source for the message of a failure, typically the path of its file, or null when it has none.
      Returns:
      The minified stylesheet.
      Throws:
      IOException - If the stylesheet is null or cannot be minified: the message names the source and says what is wrong and where (line and column).
    • minify

      public String minify(String source) throws CSSCompressor.MinificationException
      Returns source, minified.
      Parameters:
      source - a stylesheet
      Returns:
      source, minified
      Throws:
      CSSCompressor.MinificationException - if source can't be minified