views:

527

answers:

7

Possible Duplicates:
How to organize minification and packaging of css and js files to speed up website?
What do you use to minimize and compress JavaScript libraries?

Hi there

Do you know any tool/method which can help me to minimize the size of a javascript file?

+2  A: 

There are two that I know of:

The YUI compressor is slightly better in that it will compress CSS too. The .NET version can be integrated with MSBuild.

Ken Keenan
there are also an ant task and a Maven plugin
dfa
A: 

I'm successfully using the YUI Compressor.

ujh
A: 

I like JavaScriptCompressor.com simply because it's online and doesn't need any software to be downloaded or installed.

+2  A: 

I have been using JavaScriptMVC for a while, which has a built-in function to combine and compress all javascript files. But it's actually a complete framework to structure your code.

There are a lot of minifiers on the market. Here are three:

MinifyMe
Dojo also has a compressor
Compressing with JavaScriptMVC

The great benefit of JavaScriptMVC and Dojo is that they don't use Regular Expressions to perform compression. I don't know about the other ones. Compression by using regular expressions can sometimes lead to errors in your compressed/minified Javascript code and is kind of brittle

PeterEysermans
+1  A: 

There are a number of online tools available for minimising your javascript. The following tools all require a download and to be run on your machine:

  1. YUI Compressor
  2. JSMin
  3. ShrinkSafe

These tools allow you to paste in/submit your javascript online and get a minimised version back without having to run any programs on your machine:

  1. Packer
  2. JS Minifier

One potential issue with minimising your javascript is the need to keep a minimised version in your codebase for deployment, and an expanded version for development/maintenance. One way around this is to have your webserver look after compression and minimisation of the files in question. This may lead to some additional overhead on your webserver, but you can address this via cache lifetimes etc.

For Apache, Apache2::Response::FileMerge handles this, and can use JavaScript::Minifier to do the actual minimisation.

On nginx, NginxEmbeddedPerlMinifyJS will do much the same thing.

ConroyP
+1  A: 

Other answers mention various tools to minify your Javascript/css. however, don't forget you can also GZip your javascript/css, as demonstrated here for isntance - either manually or using some preparation stage when you deploy, or by using mod_gzip or an equivalent.

Yonatan Karni
A: 

Check out this site. It compares different JavaScript compression utilities on the fly.

Hippo