Is There a Good JavaScript Minifier

Is there a good JavaScript minifier?

UglifyJS2, used by the jQuery project.

Reliable and convenient JavaScript minifier

That link you post happens to be the one that I use too.

Use the MS AJAX Minifer. It's way better than the yui one. besides:

http://stephenwalther.com/blog/archive/2009/10/16/using-the-new-microsoft-ajax-minifier.aspx:

The Microsoft Ajax team (I work on
this team) has been using this tool
internally for a number of years. For
example, we use the Microsoft Ajax
Minifier to minify the Microsoft Ajax
Library before publishing it.

Well if you don't trust me, run your source code (if you don't have an actual source code to test, just grab the source at http://code.jquery.com/jquery-1.6.2.js) through both and see which is more "minified".

==

Google has the Google Closure Compiler but it analyzes your code and removes unreferenced code (to furthur reduce the size of the resultant file). However usually this is not what you want because even though the functions/variables are not referenced within that file, it may be referenced from your other js files that make up your site)

Best javascript compiler/minifier

Possibly UglifyJS? It's the minifier that the jQuery project is currently using.

Check out these speed comparisons.

Does minified JavaScript code improve performance?

Minifying improves performance for your page overall by decreasing the load time (even if only slightly).

Neither minifying nor obfuscating alter the execution time by any perceivable amount for the vast majority of JavaScript code out there.

I do recommend minifying for those reasons and more. Minifying multiple scripts together (like jQuery and its plugins) can yield even greater savings.

As pointed out, on constrained devices and/or with very large codebases minifying could yield a noticeable result.

Is there any risk in minifying JS and CSS?

If a cosmic ray were to penetrate your build server's case and hit the memory while the minification was happening, it could ruin everything. The chances of that are very small, though.

Another step in your build will always introduce complexity and have a potential for errors, especially when it modifies a file. Your testing will discover that, since you should always test what you plan to deploy to production. If you deploy the minified code, you test the minified code.

Minification is so widely used that most of the tools are pretty mature and robust, with excellent accuracy at detecting what is in-use and what is not. They are very good at not removing code that is used in an unusual way.

However, it is possible for the minifier to decide something isn't being used and be incorrect. In that case, your unit and/or integration testing should fail and you'll be able to change the code or tell the minifier to keep the section that was missing.

Those fixes are pretty quick and usually obvious, so the advantages of having a few small files (instead of many larger files) will almost always outweigh them. Since minifiers rename code significantly or remove it entirely, even simple smoke testing of your app is often enough to expose any errors.

As an example, Google's closure compiler has a tutorial on handling global and external variables, exports, and unused code you need to keep.

What are some good css and js minimizers for production code?

YUI Compressor does both JavaScript and CSS. I'm not sure if you can send it a batch of files.

You can batch process at YUI Compressor Online (yui.2clics.net), though that version only accepts JavaScript. Another Online YUI Compressor (refresh-sf.com) accepts CSS, too, but doesn't batch.

In terms of comparing the various minifiers, see jQuery : Frequently Asked Questions (FAQ) : How do I compress my code? Also, check out Microsoft Ajax Minifier.

jQuery has switched from the YUI Compressor to Google's Closure Compiler for the minified version that they distribute.

Is there any benefit to minifying source code that is read only by Node?

The point of minification is reducing bandwith (smaller file = less bytes). Since you're not sending your sever-side code to your client, there's no reason to reduce it. True, reading the file from disk will be a tiny bit faster, but if startup time is your bottleneck, you've got some bigger problems.

Having said that, closure compiler isn't only a minifier: it attempts to be a javascript compiler, trying speed up your code. The different JITs might also like your "compiled" code better, especially in function inlining. Having said that, the speed difference will likely be negligible.

In conclusion: No, but you might enjoy reaping the side-effects. I don't know of any tests, so you could be a pioneer in the field. Benchmark your unminified program over some time, then benchmark the minified version.

javascript minimizer

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



Related Topics



Leave a reply



Submit