How to Minify Javascript

minified js

Simple – to compress the code so it loads faster

JSMin (The most popular JavaScript compression tool) is a filter which removes comments and unnecessary whitespace from JavaScript files. In most instances it reduces file size by 50%, resulting in faster page load times and less bandwidth usage.

JavaScript minifying is a filter that excludes or modifies some characters in your code. Other javascript compressors will “pack” the code. These are commonly referred to as Packers. This does not change the behavior/functionality of the program/script that it is minifying.

The compressed code may be harder to debug because it is bunched together, usually on one line – This is why we always recommend keeping a backup copy of your JS script to use in times where debugging is required.

Minifying JavaScript first replaces carriage returns (‘\r’) with linefeeds (‘\n’). It replaces all other control characters (including tab) with spaces. It then replaces comments in the // form with linefeeds. It replaces comments in the /* */ form with spaces. All runs of spaces are replaced with a single space. All runs of linefeeds are replaced with a single linefeed.

Leave a Reply

Your email address will not be published. Required fields are marked *