4

Possible Duplicate:
What do you use to minimize and compress JavaScript libraries?

Sometimes you'll see two different files like "jquery.1.3.2.js" and "jquery.1.3.2-min.js". The "min" version has all the whitespace and comments removed.

Is there a tool that will do that for me or do I have to do it manually?

Community
  • 1
  • 1
Joy P.
  • 148
  • 1
  • 7
  • 6
    Dupe: http://stackoverflow.com/questions/599911/what-do-you-use-to-minimize-and-compress-javascript-libraries – GmonC Nov 25 '09 at 16:55
  • 1
    Duplicate of http://stackoverflow.com/questions/883184/ways-to-compress-minify-javascript-files-closed – Ivan Nevostruev Nov 25 '09 at 16:56

7 Answers7

12

Yes. The term you're looking for is "minify" your javascript.

Jsmin, Packer, and ShrinkSafe are all good tools. But the leader is YUI Compressor.

Rap
  • 6,851
  • 3
  • 50
  • 88
  • I wouldn't use packer anymore, as there is a cost in unpacking on every page load. – Nosredna Nov 25 '09 at 16:57
  • 6
    @Nosredna, I wish people would stop saying this about packer. It is a perfectly good minimiser. You don't have to use the base62 option, in fact it is turned off by default. It seems that people are happy to regurgitate opinions without checking the facts. – Dean Edwards Nov 25 '09 at 19:10
  • Packer with base62 option enabled is excellent if you can't serve your assets gzipped. Typically I see packer shaving an extra 30% over typical minifiers. However, I've found base62-packed files don't gzip as well. For this reason I typically use more typical minification and gzip. EDIT: Just realised I have replied to a 6-year old thread. EDIT2: Just noticed Dean Edwards comment. Maybe I should go to bed. – Phil Ricketts Jun 26 '15 at 21:24
4

There are several tool available to do this. Just to name a few:

3

here is one way: YUI Compressor

Josh Pearce
  • 3,399
  • 1
  • 23
  • 24
3

The two most popular solutions are JSMin and YUI Compressor.

Jordan Ryan Moore
  • 6,877
  • 2
  • 26
  • 27
1

You could use YUI and Google has recently released its Closure Comiler however, the latter tends to fail with jQuery

Community
  • 1
  • 1
Yacoby
  • 54,544
  • 15
  • 116
  • 120
1

http://developer.yahoo.com/yui/compressor/

Jaanus
  • 17,688
  • 15
  • 65
  • 110
1

In order to minify your Javascript code, you can use YUI Compressor or JSMin as recommended by Yahoo (http://developer.yahoo.net/blog/archives/2007/07/high_performanc_8.html)

Guillaume Flandre
  • 8,936
  • 8
  • 46
  • 54