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:

  1. 12 Tips to improve your jQuery code
  2. Speeding up Google Analytics load times with a jQuery plugin
  3. Warn visitors to upgrade from Internet Explorer 6 (IE6) with a simple JavaScript
  4. JavaScript Best Practices by Christian Heilman
  5. Checking your internal and external IP Addresses on a Unix machine
Twitter Digg Delicious Stumbleupon Technorati Facebook Email

7 Responses to “Minify JavaScript code to obfuscate details and decrease load times”

  1. 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!

  2. Sure, thanks for the link! :D

  3. 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.

Trackbacks/Pingbacks

  1. What is Javascript Minification? « Programming Tips - 04 Jun 2009

    [...] Minify JavaScript code to obfuscate details and decrease load … [...]

  2. Top 10 Free Javascript Compressors « Webpage Designer Blog - 04 Jun 2009

    [...] Minify JavaScript code to obfuscate details and decrease load … [...]

  3. Top 10 Free Javascript Compressors - 23 Jun 2009

    [...] Minify JavaScript code to obfuscate details and decrease load … [...]

  4. Willem van Zyl (willemvzyl) « Minify JavaScript code to obfuscate details and decrease load times... « Chat Catcher - 29 Oct 2009

    [...] @BobMabena Hi Bob. Does this help? [link to post] – It explains how to minify JavaScript [...]

Afrigator