22

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.

Vini
  • 8,299
  • 11
  • 37
  • 49

6 Answers6

39

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.

Dan Lew
  • 85,990
  • 32
  • 182
  • 176
  • 3
    The YUI compressor is nice because it uses the Rhino engine to validate that the compression is done correctly. – cgp May 08 '09 at 18:56
  • 2
    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 May 08 '09 at 19:08
  • 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. – Vini May 08 '09 at 21:08
  • 2
    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 May 08 '09 at 22:11
  • The online version gives me an OutOfMemoryError and prints a huge stacktrace. And it was only 600k of Javascript. Sad. – Eduardo Dec 27 '12 at 04:17
4

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
  • 84,693
  • 113
  • 396
  • 647
3

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
  • 339,989
  • 67
  • 413
  • 406
3

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

Marcus
  • 8,601
  • 4
  • 24
  • 24
0

A nice one is Zbugs: "Minify and Gzip compress CSS & Javascript in a single click". Type your URL, and you can one-click download the result. It also shows some informations about the size when gziped, minified, concatenated compared with the original.

Eduardo
  • 4,282
  • 2
  • 49
  • 63
0

This is for 2022 users looking for a way to minify Jquery-written JS code. When all other options have been exhausted, I discovered this website that completed the task quickly and flawlessly.

Minify JavaScript - Online Compressor / Packer

Its seems to be built just for the purpose.

Dev_Michael
  • 71
  • 1
  • 9