I look for tool which can compress JavaScript source code. I found some web tools which only deletes whitespace chars? But maybe exist better tool which can compress user's function names, field name, deletes unused fields, others.
-
There's very little purpose in compression or obfuscating JavaScript. What you describe would likely save you a few KB per user at best and not make it much more difficult to read the code. Why are you trying to do this? – Sep 13 '09 at 12:27
-
Multi Dup: http://stackoverflow.com/questions/883184/ways-to-compress-minify-javascript-files – Crescent Fresh Sep 13 '09 at 13:39
-
I would do it, because 1)reduce the size of *.js files, 2)dotfuscate source code – Michał Ziober Sep 13 '09 at 13:45
-
1Also consider using google's http://code.google.com/closure/compiler/ – Ruan Mendes May 05 '10 at 17:53
3 Answers
A tool often used to compress JS code is the YUI Compressor.
Considering there is this option :
--nomunge
Minify only. Do not obfuscate local symbols.
It should be able to do what you asked.
And here is an article about it : Introducing the YUI Compressor.
Quoting that article :
It starts by analyzing the source JavaScript file to understand how it is structured. It then prints out the token stream, replacing all local symbols by a 1 (or 2, or 3) letter symbol wherever such a substitution is appropriate
As a sidenote : don't forget to gzip your JS/CSS files, when serving them from your webserver : this will reduce the size of data that goes through the network quite a lot !
For instance, if you are using Apache, take a look at mod_deflate
.

- 395,085
- 80
- 655
- 663
Check out YUI Compressor, there is also ESC, but I suspect YUI is a bit better. Up to you to test.

- 54,084
- 6
- 88
- 105
Javascript minimizer have been discussed here before, but still I feel that the JavaScript compressor rater web page summarizes them best:
- JSMin is a conservative compressor, written several years ago by Douglas Crockford. It is considered safe (especially if you verify your code with JSLint first-- an excellent thing to do anyway) because it doesn't attempt to change any variable names.
- Dojo shrinksafe is a very popular Java based JavaScript compressor that parses the JavaScript using the rhino library and crunches local variable names.
- Packer (Version 3.1) by Dean Edwards, is also a very popular JavaScript compressor, that can go beyond regular compression and also add advanced on-the-fly decompression with a JavaScript runtime piece.
- the YUI Compressor (Version 2.4.2) is a newer compressor written by Julien Lecomte, that aims to combine the safety of JSMin with the higher compression levels acheived by Dojo Shrinksafe. Like Dojo shrinksafe, it is written in Java and based on the rhino library.