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:

Share this article: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Twitter
  • GatorPeeps
  • Digg
  • Reddit
  • muti.co.za
  • DZone
  • del.icio.us
  • StumbleUpon
  • Technorati
  • Ma.gnolia
  • Slashdot

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. Subdomain tracking update to the geekGa.js jQuery plugin for Google Analytics