All web applications has
JS files. But, now a days most of the developers wants to include only
minified JS and CSS files. Because, normal
CSS files having unnecessary characters in source codes. These unnecessary characters usually include
white space characters, new line characters, comments, and sometimes block delimiters. These are very important only for code readability, but not needed for execution process. These unnecessary characters increase file size and it will be affect performance too. For this reason, the minification (also minimisation or minimization) is very important.
We have lot of
CSS minification online convertor and have lot of
JAVA libraries available in internet. But, best one is,
YUI Library ( Yahoo userInterface Library ). Because, it is very lightweight core library and also it is a free open source Library.
YUI Compressor is also able to compress CSS files by using a port of Isaac Schlueter's regular-expression-based CSS minifier.
In this file, First need to include
YUI jar file. In the below sample code, I have paste my downloaded
YUI jar file inside of the lib folder.
So, using this.settings I have included my jar file into my application. And As usaual, I have created an object for 2 CFC files. Inside of those files, I wrote a code for minified process.
In this file, I wrote two functions such as
cssCompressor(). In the
cssCompressor() function, I wrote
CSS file minification process code and in the another function wrote a
JS file minification process code.
In side of this function, I created an object for ErrorReporter.cfc file. This is a required core file. So, Please don't forgot to include this CFC file on the particular directory. I just read all the
CSS files from /assets/js & /assets/css directory and then created some wonderful Java objects like StringBuilder,StringReader,StringWriter. These all are used for minified the CSS & JS files.
CSSfiles need to call the CssCompressor