Javascript Compression
Solution 1:
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
.
Solution 2:
Check out YUI Compressor, there is also ESC, but I suspect YUI is a bit better. Up to you to test.
Solution 3:
Javascript minimizer have been discussedherebefore, 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.
Post a Comment for "Javascript Compression"