Lighthouse: Minify JavaScript


PageSpeed (Legacy)
YSlow (Legacy)


Minifying JavaScript files is an optimization technique to reduce JavaScript payload and the main-thread blocking time.

Minification can help reduce JavaScript file sizes by removing comments, white spaces, and redundant code, and in some cases, also makes the code more efficient by using shorter variable and function names.

The smaller these JavaScript files are, the faster they are downloaded, parsed, and executed by the browser.

How does your site score on this audit?

How does minifying JavaScript affect page performance?

Whenever the browser loads a page, it needs to download, parse, and execute JavaScript files during the page load.

Since this happens on the main-thread by default, a higher JavaScript payload will block the main-thread for longer, extending your page load.

Minification makes your code leaner and more compact by removing unnecessary elements, decreasing the file size, reducing the bandwidth consumed, and speeding up your overall page load times.

A lower JavaScript file size/payload reduces the time spent parsing scripts, resulting in faster page loads and improved page experience.

How minifying JS reduces filesize/payload/parse time
Minification of JavaScript files reduces payload and script parse time, resulting in faster page loads.

Minify JavaScript with care

JavaScript minification could break your site in some cases, if not done properly.

Minifying your JavaScript is less impactful on the overall page experience when compared to other optimizations like code-splitting, eliminating dead code, and caching your JavaScript code.

Hence, Minification is a lower priority optimization that should be regarded as a fine-tuning step to refine your page experience rather than single-handedly boost your page performance.

How does GTmetrix trigger this audit?

GTmetrix evaluates all the JavaScript files on your page and calculates how much bandwidth is wasted by each JavaScript file that isn't minified.

Clicking the audit reveals the list of JavaScript files that can be minified.

Expanded view of Minify JS audit
GTmetrix reports the file size savings possible through JavaScript minification.

GTmetrix also estimates the JavaScript file size savings possible through minification.

How to minify JavaScript?

To fix this audit, follow one of the below JavaScript minification methods:

1) JavaScript minification using online tools

Identify the JavaScript files flagged by GTmetrix and locate them in your page's HTML.

Copy the JavaScript code of the unminified file and paste it into a JavaScript minifying tool like to generate the minified JavaScript file.

Now, copy the minified JavaScript code and paste it into the respective JavaScript file on your website. Repeat this process for all the unminified JavaScript files.

If you have a large number of JavaScript files to minify, then consider using more advanced minification tools.

2) JavaScript Minification using build tools

If you're a more advanced user, you can use build tools like UglifyJS and Google's Closure Compiler, among others, to minify your JavaScript files.

3) JavaScript Minification using a CDN

An easy way to serve minified JavaScript files is by using a CDN. The actual JavaScript files on your origin server may still be unminified but the CDN will create and serve the minified JavaScript versions of those files to your page visitors.

The advantage of using a CDN here is that the original and minified JavaScript files are kept in sync i.e., any changes to your original files will be reflected in the minified versions.

4) For WordPress (or other CMS users)

WordPress (and other CMS) users can also use plugins like WP Rocket to automatically minify JavaScript files.



Using WordPress? Improve this Audit with WP Rocket

WP Rocket can minify your JavaScript files with just a few clicks.

Get full page caching for your WordPress website (and more) to speed up overall loading times.

Get WP Rocket »

Cookie Policy

By clicking "Allow All" you agree to the storing of cookies on your device to enhance site navigation, analyze site usage, and assist in our marketing efforts. View cookie details

Deny Allow All