jcmin – A Javascript and CSS minimizer using Google Closure and YUI Compressor

Hi Guys,

I am working on relatively medium to enterprise size project where we have 70+ javascript and 20+ css files plus libraries we use. I had this problem where I just want to minimize all files at once or individually using YUI compressor and Google Closure.

I couldn’t find anything that utilizes both and do compression without making API calls.

Thus I end up developing jcmin for myself which mean Jaspreet Chahal’s a Monster 🙂 Just kidding. It actually means Javascript CSS  Minimizer

I didn’t do anything fancy I thought this util can help someone who want simple command line rather than remembering all the little things provided by individual compilers.

jcmin is in Beta. Not the actual compilers (Closure and YUI Compressor) but jcmin. 

Important: jcmin is not a compiler itself.

You can say jcmin is a wrapper to YUI compressor and Google Closure and it only does basic stuff. I can add more Advance things  if you like this util and want more control. As I said I developed this util for myself and I am kinda sharing it. If you end up finding it useful then consider donating or atleast a backlink to this page will much appreciated.

 

Pre-requisites

  • .NET Framework >= 2.0
  • Recommended: java.exe in System environment path.

Advantages of using this util

  • Gives you option to choose between Google Closure and YUI Compressor
  • You can minimize files under your directories
  • You can even re curse through your directory and minimize files inside subdirectories. This util will form an equivalent structure at target directory.
  • No need to goto separate compilers for Javascript and CSS this util do it both by firing appropriate compiler for a given file type.
  • See Errors thrown by respective compiler.
  • Comes with IKVM so if you dont have java installed compilers still work (I recommend to install it and put java.exe in Environment Path)
  • You can skip any number of file by their name or even part of their name. so -excl=jque|ext will skip file names that contains jque and ext
  • I am tired of typing this stuff, you will find out what Disadvantage you will come up with, so there is no point highlighting the advantages 🙂

Advertisement

 

Compilers used

  • Closure
  • YUI compressor (when you select switch -use=yui Closure will not be used)
  • Closure Stylesheets

Interesting reading(s)

Problems and Solutions

http://jaspreetchahal.org/examples-jcmin-a-command-line-js-and-css-minimizer-built-on-top-of-google-closure-and-yui-compressor/

 

Downloads

If you have java.exe in Environment Path If you don’t have java.exe. Build comes with IKVM.
Download Download
Recommended: Get Java Runtime Environment and put java.exe in Environment
Path variable

 

Support me, well I know you won’t but its worth asking because I’ve got pending bills for bandwidth that I use :).

Buy me a bottle of Ice Tea 🙂

$ 190.00 raised.
Choose donation amount:

Command options

Lets see what this command line util is capable of.

Things you should know

  • Default encoding type for YUI compressor is UTF-8. Use –autf8 to avoid it.
  • When you minimize CSS with Google Closure following options are used by default
    • –allow-unrecognized-functions (this is to avoid errors when CSS functions such as scale are used )
    • –allow-unrecognized-properties (this is to avoied error when non standard CSS rules are used)
      Reason:  Well I included those function and properties for a reason in my CSS file with side effects known so why do I need to see my CSS not getting minimized because of that.
      Future versions (If you guys support this Util): Will give you control on passing such flags to the individual compilers.

Advertisement

 

Advanced Usage

Each compiler comes with some advanced options. I am keeping this version as simple as I possibly can. If you think an option can be added to this command either contact me directly through contact form or leave you comment.

Disclaimer

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE X CONSORTIUM
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

So bottom line is that I am not responsible for any damage you may cause to your files. It is always a good idea to backup your files to be on safe side.

I rushed through this post, so if you see any spelling mistakes please let me know

Cheers!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.