Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a good JavaScript minifier? [closed]

What JavaScript minifier do you recommend?

like image 538
user160820 Avatar asked Aug 19 '10 09:08

user160820


People also ask

Should JavaScript be minified?

Minification does improve performance for two reasons: Reduced file-size (because it removes comments and unnecessary white spaces), so your script loads faster. Even if it is embedded into the <head> . It is parsed faster, since comments and white spaces don't have to be explicitly ignored (since they're not there).

Is HTML minification worth it?

Since any minification takes server resources, it's worth minimizing only those assets which are relatively unchanging like CSS and JS. HTML changes too frequently to be worth it IMHO.

Should you minify code?

Minification is the process of minimizing code and markup in your web pages and script files. It's one of the main methods used to reduce load times and bandwidth usage on websites. Minification dramatically improves site speed and accessibility, directly translating into a better user experience.


3 Answers

UglifyJS2, used by the jQuery project.

like image 148
Andreas Hofmann Avatar answered Oct 17 '22 14:10

Andreas Hofmann


Active

  • Closure Compiler
  • UglifyJS2

Deprecated

  • YUI Compressor
  • UglifyJS

Google Closure Compiler generally achieves smaller files than YUI Compressor, particularly if you use the advanced mode, which looks worryingly meddlesome to me but has worked well on the one project I've used it on:

Several big projects use UglifyJS, and I've been very impressed with it since switching.

like image 23
Tim Down Avatar answered Oct 17 '22 12:10

Tim Down


JavaScript Minifier gives a good API you can use programatically:

curl -X POST -s --data-urlencode 'input=$(function() { alert("Hello, World!"); });' http://javascript-minifier.com/raw

Or by uploading a file and redirecting to a new file:

curl -X POST -s --data-urlencode '[email protected]' http://javascript-minifier.com/raw > ready.min.js

Hope that helps.

like image 12
chilts Avatar answered Oct 17 '22 12:10

chilts