Minify JavaScript

How to Minify JavaScript and why you should do it

Method Type: User (.JS)
(this means that the method is handled by the user with the help of a minifying tool or by enabling Mod pagespeed in the .htaccess file)

 

ModPagespeed On

Apache's PageSpeed module is supported by all FastComet hosting plans

 

Status: Must be applied/enabled by the user.

 

Introduction:

JavaScript is a dynamic, high level programming language. It is one of the three essential technologies used for producing content for the World Wide Web.  A JavaScript file (.js) is used mainly for running JavaScript code to execute instructions.

 

How Minifying JavaScript works:

The minification of a script is the removing of all unnecessary characters from the code to reduce the size thus significantly improving the loading times of the elements on the page.  The minification removes all spacing, new lines and developer comments to reduce the size as much as possible.

 

Minifying JavaScript provides the following Advantages:

Reduces file size
Speeds up parsing, downloading and execution time
Increases loading and compression speed

 

Note that you won't be able to minify external JavaScript elements as you can see from the example below.

 

Impossible to minify Javascript

 

These elements will lower your score but are beyond your control.

 

One of the most useful PageSpeed filters is the rewrite_javascript one, which minifies JavaScript without any additional input from the user.

 

You can enable the Mod pagespeed by accessing the .htaccess file and adding the following line to it:

 

ModPagespeed On

 

You can also minify JavaScript for your website with this tool. Here you can paste you JavaScript and minify it.

 

Pasting a JavaScript ready to be minified

 

You can also upload multiple JavaScript files and compress them into one minified file.


Uploading multiple JavaScripts for minifying

 

You can check the results in the output tab of the tool.

 

Congratulations, you have minified your JavaScript scripts.