Wednesday, December 6, 2017

Minimize CSS & JS resources with cssjs-minifier

In this article I'll introduce to you one of my newest app called cssjs-minifier. I developed it for myself first, but then I make it open source through GitHub for helping other web developers.
The application is compressing web resources. It uses two well known minifier(YUI Compressor, Google Closure Compiler)  to compress the CSS and JS resources. The main reason I created is that most of the compressors is online, and I didn't find any fast, small,offline and portable solution for this problem. You can set the compress mode with a config file, so it's easy to use as well. The app'll skip all the files which contains the "min" keyword. I mean a "min.js" won't be skipped, only the files ends with ".min.js". With this feature the compiler'll skip the already compressed files.

Let's see the installation! Open your web browser and go to the GitHub project site https://github.com/szrnka-peter/cssjs-minifier/releases. Download the JAR file and the related config.properties file, and additionally the run.bat file if you need it. Open the config, and customize it for your needs.

The necessary properties:

  • jscompressor 
  • jsfolder The input folder of Javascript files 
  • jsout The output file of the compressed Javascript files.
  • jscompiletype WHITESPACE | SIMPLE | ADVANCED
  • csscompressor
  • cssfolder The input folder of CSS files
  • cssout The output file of the compressed CSS files.

YUI

This is the compressor tool of Yahoo. The application supports both the CSS and JS minification with this library. For use it, set the "jscompressor" or "csscompressor" value in the config.properties to "yui".

Google Closure Compiler

It's a great tool for compressing files. Currently the application supports only the Javascript compression.

Usage

If you've done with the configuration, then run the JAR file with the following command:
java -jar cssjs-minifier.jar
(For Windows users, it's a great idea to put this in a .bat file for easier use.)

Configure and use VSCode for Java web development

Embarking on Java web development often starts with choosing the right tools that streamline the coding process while enhancing productivity...