Hackernoon logoJavaScript Compressors: How and Why to Minify Your JS by@rahhulsom47_55087

JavaScript Compressors: How and Why to Minify Your JS


A JavaScript could be said to be the simplest form of programming language. It is most widely used by web developers for the purpose of writing scripts and creating interactive websites.

JavaScript is often confused with Java. However, the two are completely different. A Java is a complex programming language which can be used for a wide variety of tasks on the other hand JavaScript is a simple and lightweight script language.

JavaScript was developed by Netscape. JavaScript is capable of interacting with Html and thus can be used to add many dynamic features to a website.

A JavaScript can run with any web browser having inbuilt JavaScript support. The good news is that nowadays all the browsers come with JavaScript support.

JavaScript is mainly used for creating interactive websites, creating cookies, adding animation to a website, enabling interactive features like Twitter or Facebook to a site, quickly adding text to an Html page, allowing visitors to load images or other objects with refreshing or reloading the whole website, etc.

However, if you have used JavaScript script on a particular website and you find it loading unbearably slow, it’s the time to use minification. Minification also called as minifying is a simple process to decrease the size of JavaScript so as to make it load faster. Minifying is the best way to speed up the response time of a website.

Let’s make it simple. A computer is an extremely fast and intelligent machine. It can easily read and understand even the most complex programs in a matter of seconds.

It absolutely doesn’t matter how the program is written, whether there are spaces or not and what names are given to the defined variables.

We usually write programs in a way such that it can be easily read and understood by humans. The programs are arranged using suitable spaces and lines. We often add comments for better understanding. However, the main purpose of a programming code is to be understood by the computer and as earlier said a computer could read any programming code easily no matter how they are written or arranged. It just needs to be free from any syntax errors.

The spaces, comments and other elements we use in the programming code affects its size. We unknowingly almost double the size of a program just because of these things. The process of minifying removes these spaces and comments from a JavaScript and ultimately reduces its size to a lot of extents.

By drastically reducing the size of a program file you can decrease its loading time. This way a user will be able to download it at a much faster rate in comparison to a default JavaScript.

However, the minification process is not used on small codes as it effects are hard to recognize. Small codes are already small in size, and thus there is no need to further decrease their size by minification. Minifying a large JavaScript works wonders, and its impact can easily be seen. You can yourself check for the file size before and after minifying it. Minification process can reduce the file size from 20% to even 50%.

Here is an example. A simple JavaScript code without any minification looks like this.


The same code looks something like this after minifying it.


It might seem really confusing and hard to understand on the other hand you can easily read the same code in the previous image. This is because all the line spacing and spaces between characters and brackets have been deleted. However, both the codes are treated in the exact same way by a computer system. A computer can easily read both the code without any difficulty.

Minifying your website’s JavaScript is highly beneficial. It makes your website faster and better. The prime goal of any site is to get as much traffic as possible. This is only possible when it works seamlessly without any issues.

There is nothing more annoying than slow loading of the website. I mean nobody really likes to visit or use a website which is very slow to load just because of its large size. A user will start hating your website no matter how useful its contents are and how well the site is designed.

So now you have learnt about minification and its benefits. The next big question is how to minify a JavaScript code. Doing it manually is a hectic task. It might also affect the code, and it may start behaving abnormally. Well not to worry as there are many free tools available which you can use to minify JavaScript code in just a few seconds. But you need to be careful as you will not be able to restore a code once it is minified. Thus it is advisable to make a copy or backup of it. Once you are ready here are some of best JavaScript minification tools which you can use to minify.

JS Compress

JS Compress is one of the fastest and easiest ways to minify a JavaScript code. It is a website which is specially developed for this purpose. What you just need to do it copy the code and press convert. It’s done your JavaScript code is now minified.

JavaScript Minifier


It is another very easy to use website. The interface is really clean and simple. It just contains a box to paste the code and a button to minify. Copy paste the JavaScript code and then click the minify button. It’s done.

Minify is online tool widely used for the purpose of minifying JavaScript. The website is designed with great features, and it just takes a few seconds to convert even the biggest code.

There is also some minifying tools which are present as plugins which can be used directly with your JavaScript editor.

Overall minification is a very simple and highly effective method to reduce the JavaScript file size and increase your website speed. A JavaScript code can be minified by anyone no matter whether you possess the knowledge of programming or not.

Author Bio :- Rahul Som is a CEO and co-founder of Hopinfirst, one of the top Mobile App development Company which provide best ios app development and Android app development Services. Rahul is passionate about Startups, Technology and management and blogs frequently on the topics.


Join Hacker Noon

Create your free account to unlock your custom reading experience.