Friday, January 9, 2015

14 Tools For Minifying Javascript


Javascript minification is a technique which condenses your script into a much smaller footprint. You lose human readability but you conserve considerable bandwidth – in the end, Javascript is meant for your browser not for your users.

Most production websites use Javascript minification but the way this is achieved varies greatly. From simple online converters to more comprehensive GUI tools to command line interfaces, our options are pretty varied. In this article we’ll take a look at how Javascript minification works, how we can build it into our workflow and what the pros and cons of minifying are.

How Minification Works

The best way to learn what happens when you minify your code is to take a look at the UglifyJS Github Repository. This script is used in many online converters as well as GUI tools and command line tools like Grunt. Here are some of the transformations it applies to make your code shorter:
  • Removes unnecessary space
  • Shortens variable names, usually to single characters
  • Joins consecutive var declarations
  • Converts arrays to objects where possible
  • Optimizes if statements
  • Calculates simple constant expressions
  • etc.
As a quick example, here’s a function that essentially writes some given text out.

Read More

No comments:

Post a Comment