Minify your Javascript code
Minification is the process of eliminating white space, comments, and other nonessential parts of the JavaScript code to decrease the size of the JavaScript files that need to be transferred from the server to the browser. This may help you decrease the load time of your web page and there are a lot of tools to help you in this process, called Minifiers.
One thing to remember is that in order to achieve best results, a good practice is to use local variables in your code whenever possible, because Minifiers also rename variables to shorter names… but only when it’s safe to do so. Global variables are not minized as this may break the code. Shorter names will also speed up the lookups when resolving a variable name, and so the code will be faster during runtime.
It is written in Java and provides a small .jar file that can be used to minify your javascript and css files doing the following steps:
- Analyze the source JavaScript file to understand how it is structured
- Then prints out the token stream, omitting as many white space characters as possible and replace all local symbols by a 1 (or 2, or 3) letter symbol wherever such a substitution is appropriate
- Outputs result in a *.min.js file
The CSS compression algorithm uses a set of finely tuned regular expressions to compress the source CSS file
Usage
java -jar yuicompressor-x.y.z.jar [options] [input file]
Example
java -jar yuicompressor-2.4.6.jar -o hello.min.js hello.min.js Minify file "hello.js" and output the result in "hello.min.js" file.
Download it here
The Closure Compiler is a tool for making JavaScript download and run faster. It is a true compiler for JavaScript. Instead of compiling from a source language to machine code, it compiles from JavaScript to better JavaScript. It parses your JavaScript, analyzes it, removes dead code and rewrites and minimizes what’s left. It also checks syntax, variable references, and types, and warns about common JavaScript pitfalls.
Usage Example
java -jar compiler.jar --js hello.js --js_output_file hello-compiled.min.js Minify "hello.js" to hello-compiled.min.js
Download it here
MinifyJS.com provides some advanced features to give you even further control over how you compress your Javascript in a minimalistic UI.
- Simply Copy and paste your Javascript code into the top box
- Select any advanced options like, compression method, packing/compressing speed, special chartacters
- Press “Compress Javascript” button.







