Search code examples
javacssfacelets

How can I remove comments on-fly from my static CSS files?


I'm using facelets, and I have a number of CSS files in webapp/styles/blueprint/*.css. They contain comments which I don't want to become visible to end-users. How can I remove them on-fly?


Solution

  • Use YUI compressor. It will not only remove comments, but also minify the CSS (and JS) files.

    Reader reader = null;
    Writer writer = null;
    
    try {
        reader = new InputStreamReader(new FileInputStream(cssFile), "UTF-8");
        writer = new OutputStreamWriter(new FileOutputStream(minFile), "UTF-8");
        new CssCompressor(reader).compress(writer, -1); // That's it.
    } finally {
        close(writer);
        close(reader);
    }
    

    See also