Minify JS Online

Free tool to minify (compress and optimize) JavaScript code, reducing file size and improving load speed while keeping functionality intact.

What is Pdfutility.in?

Pdfutility.in is a simple, powerful online tool designed to reduce the size of JavaScript files by up to 80%. The tool uses the Terser engine, which fully supports modern ES6+ syntax. Along with minification, Pdfutility.in also provides helpful guides, best practices, configuration tips, and examples that make it easier to understand and implement JavaScript minification in real projects.

What is JavaScript Minification?

JavaScript has evolved from a basic browser scripting language to a universal programming language used in websites, apps, servers, and even desktop applications. But as web applications grew more complex and user devices shifted toward mobile, developers started facing two major limitations: bandwidth size and connection speed.

Modern web apps often load large JavaScript bundles. Mobile users, especially those on slower networks, feel this slowdown the most. Even search engines now consider page size and loading speed when ranking sites. That’s why code optimization and minification became essential for performance.

Minification removes unnecessary code characters—like extra spaces, line breaks, long variable names, and comments—while keeping full functionality. In many cases, minifying JavaScript can reduce file size by 50%–80%, resulting in faster page loads, improved user experience, and better SEO performance.

JavaScript Minification Example

Here’s a simple before-and-after example illustrating how minification works:

// Original code
var isFriendly = true;

if (isFriendly) {
    console.log('Hello world');
}
// Minified output
var isFriendly=!0;isFriendly&&console.log("Hello world");

In this example, unnecessary whitespace and line breaks are removed, the boolean true is shortened to !0, and the if statement is optimized into a compact expression. The final minified version does the exact same job while occupying significantly fewer bytes.

What Is the Best Way to Minify JavaScript?

There are several JavaScript minification tools available. Google’s PageSpeed Insights recommends UglifyJS and Closure Compiler. Server-side solutions like Apache and Nginx PageSpeed modules can also perform automatic optimization.

However, as JavaScript has evolved, many older tools have fallen behind. UglifyJS does not fully support ES6+ syntax, and Closure Compiler’s JavaScript package has been deprecated. Terser emerged as the modern successor to these tools. It is a fork of the now-deprecated uglify-es and offers full ES6+ support, active community backing, and compatibility with many existing build configurations.

Today, Terser is the default minifier used in popular bundlers and frameworks like Webpack, Angular, Next.js, and many more—making it the practical choice for modern JavaScript development.

How to Set Up Minification Using Terser

Terser provides both a CLI (command-line interface) and a JavaScript API, making it easy to integrate into your build process. To use it from the command line:

terser [input files] [options]

By default, minified output is printed to the terminal. To save it to a file, use:

terser script.js --output script.min.js

Here’s an example using Terser inside a JavaScript file:

import { minify } from "terser";

const code = "function add(first, second) { return first + second; }";
const result = await minify(code, { sourceMap: true });

console.log(result.code);
console.log(result.map);

The minified output looks like this:

function add(n,d){return n+d}

As you can see, Terser removes unnecessary whitespace and shortens variable names while preserving behavior. The result is a more compact and efficient script—ideal for production environments.