Wednesday, February 18, 2009

How to use YUICompressor to compress your javascript code?

Since writing on this blog I posted two jQuery plugins and I needed to compress my js files. So as jQuery documentation suggests I used YUICompressor. YUICompressor is javascript and CSS file/code compressor written in Java language. So to run one yourself you will need JRE installed on your machine.

Then call this command:

java -jar /path/to/yuicompressor.jar path/to/file.js -o path/to/minimized.file.js

Your file will be compressed and saved to path you specified as the last parameter (in our case minimized.file.js).

Links:

  1. Download YUICompressor
  2. Download JRE (required to run java applications)
  3. Online version of YUICompressor

5 comments:

  1. i use dean edwards packer to compress my javascript files - http://dean.edwards.name/packer/

    ReplyDelete
  2. For those without JRE, I've created a small .net console application that uses the .NET YUI compressor libraries. See http://bit.ly/2ITdV
    The .NET library can also be used for MSBUILD steps..

    Cheers, Erik

    ReplyDelete
  3. Heh, thanks for the post, turns out they have an Online compressor too: http://refresh-sf.com/yui/.

    Takes 2 seconds, and they have decent options aswell. I got 16% cut, pretty sweet.

    ReplyDelete
  4. Exactly what I was looking for! I have a custom jquery script that is 146kb, I shrunk it down to 60kb.

    Thank you

    ReplyDelete
  5. can we compress JQuery template with the help of YUICompressor

    ReplyDelete