How to Minify Your Code in JavaScript


show more Developers compact or minify their code in order to decrease the size of the JavaScript and improve page load times. You can minify your code by removing comments, renaming long variables and functions, and combining multiple statements into a single line. Or you can use one of the tools introduced in this tutorial to automate most of the process. Learn about using Closure Compiler and other tools to minify your code. show less
please wait ...

Minifying your code

If you have ever looked at the source of a web page, you might have seen some code that looks like this, all squeezed together and essentially unreadable. Now this is actually JavaScript here, but that doesn't mean somebody wrote it this way. This is the result of minification; the code has been minified. This is a process to go through some regular JavaScript and minimize it to compact it. We would first start by removing comments. Then we might rename long variable names and function names to shorter names, then get a little line breaks, and start to combine multiple statements onto one line.

Now, minification is done for one reason, to decrease the size of the JavaScript. The reason that you do it is to improve page load times, because the script gets downloaded faster. The two things minification is not: This is not compiling your JavaScript into a machine code, or anything like that. It is functionally identical. It's just a smaller amount of characters. And number two, it'...

Minifying your code
Video duration: 4m 28s 5h 31m Beginner

Viewers:

Developers compact or minify their code in order to decrease the size of the JavaScript and improve page load times. You can minify your code by removing comments, renaming long variables and functions, and combining multiple statements into a single line. Or you can use one of the tools introduced in this tutorial to automate most of the process. Learn about using Closure Compiler and other tools to minify your code.

Subjects:
Developer Web
Software:
JavaScript
Author:
please wait ...