Class CSSCompressor


  • @Immutable
    public final class CSSCompressor
    extends Object
    Utility class to compress CSS content
    Author:
    Philip Helger
    • Method Detail

      • getCompressedCSS

        @Nonnull
        public static String getCompressedCSS​(@Nonnull
                                              String sOriginalCSS,
                                              @Nonnull
                                              ECSSVersion eCSSVersion)
        Get the compressed version of the passed CSS code.
        Parameters:
        sOriginalCSS - The original CSS code to be compressed.
        eCSSVersion - The CSS version to use.
        Returns:
        If compression failed because the CSS is invalid or whatsoever, the original CSS is returned, else the compressed version is returned.
      • getCompressedCSS

        @Nonnull
        public static String getCompressedCSS​(@Nonnull
                                              String sOriginalCSS,
                                              @Nonnull
                                              ECSSVersion eCSSVersion,
                                              boolean bRemoveUnnecessaryCode)
        Get the compressed version of the passed CSS code.
        Parameters:
        sOriginalCSS - The original CSS code to be compressed.
        eCSSVersion - The CSS version to use.
        bRemoveUnnecessaryCode - if true unnecessary empty declarations are omitted
        Returns:
        If compression failed because the CSS is invalid or whatsoever, the original CSS is returned, else the compressed version is returned.
      • getRewrittenCSS

        @Nonnull
        public static String getRewrittenCSS​(@Nonnull
                                             String sOriginalCSS,
                                             @Nonnull
                                             CSSWriterSettings aSettings)
        Get the rewritten version of the passed CSS code. This is done by interpreting the CSS and than writing it again with the passed settings. This can e.g. be used to create a compressed version of a CSS.
        Parameters:
        sOriginalCSS - The original CSS code to be compressed.
        aSettings - The CSS writer settings to use. The version is used to read the original CSS.
        Returns:
        If compression failed because the CSS is invalid or whatsoever, the original CSS is returned, else the rewritten version is returned.