Minify JavaScript code to obfuscate details and decrease load times
Author: willem In: coding, javascript, php, productivity, tips & tricks, tools, unix, web developmentIf 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:
Like this post? Subscribe to the Geekology RSS 2.0 feed!













What is Javascript Minification? « Programming Tips
June 4th, 2009 at 00:12
[...] Minify JavaScript code to obfuscate details and decrease load … [...]
Top 10 Free Javascript Compressors « Webpage Designer Blog
June 4th, 2009 at 07:58
[...] Minify JavaScript code to obfuscate details and decrease load … [...]
Robert
June 4th, 2009 at 22:59
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!
willem
June 4th, 2009 at 23:16
Sure, thanks for the link!
Top 10 Free Javascript Compressors
June 23rd, 2009 at 22:26
[...] Minify JavaScript code to obfuscate details and decrease load … [...]
sunnybear
September 9th, 2009 at 02:13
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.
Willem van Zyl (willemvzyl) « Minify JavaScript code to obfuscate details and decrease load times... « Chat Catcher
October 29th, 2009 at 10:33
[...] @BobMabena Hi Bob. Does this help? [link to post] - It explains how to minify JavaScript [...]