Minify JavaScript code to obfuscate details and decrease load times
If you write a lot of jQuery (or plain JavaScript) code, there are several advantages to minifying it before you release your project to the public:
- Reduced dataload when browsers request pages (due to smaller filesizes)
- Obfuscation of potentially sensitive logic and algorithms (which could, however, be easily reversed – see below)
Minification involves removing all characters that are required for readability, but not executability. Examples are white spaces, new lines, comments, and unnecessary block delimiters.
There are several free tools available to minify JavaScript code, with some of the most popular ones being JSMin, jsobf, and the YUI Compressor.
The source code for JSMin is available in several languages:
jsobf is complemented by jsfmt, a script that will re-format minified JavaScript code. This can be useful if you need to modify a minified file or if you need to properly format an untidy file.
Online tools to minify JavaScript code include:
Related posts:



18 May 2009 








author
Thanks for the jQuery tip Willen – i never even occured to me that browsers would globally cache JS files and reuse the same Javascript across multiple domains/sites as long as the original referenced site is the same (http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js)
As jQuery is normally one of the largest javascript files downloaded by all my sites, this tip could help me see some significant performance gains!
Sure, thanks for the link!
There is open source project that incorporates all powerful tools for JS minify and merging (also with a lot of other clientside optimization actions) – Web Optimizer ( http://code.google.com/p/web-optimizator/ ). It can be used to automate your website acceleration.