views:

5610

answers:

4

Hi,

We are using jQuery in our project. We have numerous custom javascript files in our web-app that have UDFs utilizing the jQuery features. We need to reduce the size (as a part of performance improvement activities) and I am looking for a reliable 'minifier' for these files (it would be great if the same tool could minify the CSS files too)

We tried JSLint and JSMin - but JSLint does not complete and throws many exceptions as soon as it encounters jQuery code.

Regards,
- Ashish

+1  A: 

minify does the job. There's also YUI Compressor, but I've never tried it.

From the minify website:

Minify is a PHP5 app that can combine multiple CSS or Javascript files, compress their contents (i.e. removal of unnecessary whitespace/comments), and serve the results with HTTP encoding (gzip/deflate) and headers that allow optimal client-side caching. This helps you follow several of Yahoo!'s Rules for High Performance Web Sites.

karim79
+15  A: 

The YUI Compressor is a tool I use, it compresses both JS and CSS well, and it is written in Java (so you can work it into a build process via ant).

Someone's even made an online version of it.

Daniel Lew
The YUI compressor is nice because it uses the Rhino engine to validate that the compression is done correctly.
altCognito
I have used YUI Compressor as well and swear by it. It does a good job and produces working code. I've used other compressors that only do a static analysis of the code and they break things. YUI Compressor doesn't just manipulate the text it loads it up in Rhino and knows how to rename things intelligently.
Kekoa
Wow !! YUI Compressor has all the features I needed. Thanks a lot folks for the help. I have already minified all the JS files and the results look really good.Thanks all for your help once again.
Vinnie
Don’t forget to serve your files gzipped as well (if your server isn’t doing that already). I haven’t done a huge amount of minifying and gzipping, but when I was last playing with it, gzipping reduced JS and CSS files to around 33% of the original size. Minifying before gzipping brought them down another 7% or so.
Paul D. Waite
+2  A: 

Try YUICompress which usually works like a charm. Can minify CSS as well.

Marcus
+2  A: 

There's also a .NET port of YUI Compressor which allows you to:-

  • intergrate the minification/file combining into Visual Studio post-build events
  • intergrate into a TFS Build (including CI)
  • if you wish to just use the dll's in your own code (eg. on the fly minification).

because this is a port of the (original) java version YUI Compressor, which a few peeps mention above, it should give you the same results BUT all in the .NET environment -- no need for java.

HTH.

Pure.Krome