Minify JavaScript

Convert multi-line JavaScript into compact inline code

Tags: compress code javascript minify code typescript

Introduction

This online JavaScript minifier tool helps you compress and optimize your JavaScript code quickly and efficiently. It’s a great way to reduce file size, improve website performance, and streamline your scripts.

How to Use This Tool

  1. Paste your JavaScript code directly into the editor or type it in.
  2. Click the Minify button to compress your JavaScript code.
  3. After minifying, you can:
    • Download the optimized result.
    • Save or share it using a unique link.
    • Sign in with Google or GitHub to save your minified code for future use.

What is JavaScript?

JavaScript is a versatile programming language that allows developers to create dynamic and interactive features on web pages, such as animations, form validations, and real-time updates. It works alongside HTML and CSS to provide a complete user experience.

JavaScript is a core technology of the web and is widely used for both front-end and back-end development. It’s supported by all modern browsers and is essential for creating interactive and responsive websites and applications.

Learn more about JavaScript from the official JavaScript guide .

JavaScript Syntax

      
// program to solve quadratic equation
let root1, root2;

// take input from the user
let a = prompt("Enter the first number: ");
let b = prompt("Enter the second number: ");
let c = prompt("Enter the third number: ");

// calculate discriminant
let discriminant = b * b - 4 * a * c;

// condition for real and different roots
if (discriminant > 0) {
    root1 = (-b + Math.sqrt(discriminant)) / (2 * a);
    root2 = (-b - Math.sqrt(discriminant)) / (2 * a);

    // result
    console.log(`The roots of quadratic equation are ${root1} and ${root2}`);
}

// condition for real and equal roots
else if (discriminant == 0) {
    root1 = root2 = -b / (2 * a);

    // result
    console.log(`The roots of quadratic equation are ${root1} and ${root2}`);
}

// if roots are not real
else {
    let realPart = (-b / (2 * a)).toFixed(2);
    let imagPart = (Math.sqrt(-discriminant) / (2 * a)).toFixed(2);

    // result
    console.log(
    `The roots of quadratic equation are ${realPart} + ${imagPart}i and ${realPart} - ${imagPart}i`
  );
}
      
    

What is Minification?

Minification is the process of minimizing code and markup in your web pages and script files. It’s one of the main methods used to reduce load times and bandwidth usage on websites. Minification dramatically improves site speed and accessibility, directly translating into a better user experience. It’s also beneficial to users accessing your website through a limited data plan and who would like to save on their bandwidth usage while surfing the web.

Why minify JavaScript?

When creating JavaScript developers tend to use spacing, comments and well-named variables to make code and markup readable for themselves. It also helps others who might later work on the assets. While this is a plus in the development phase, it becomes a negative when it comes to serving your pages. Web servers and browsers can parse file content without comments and well-structured code, both of which create additional network traffic without providing any functional benefit.

To minify JavaScript files, comments and extra spaces need to be removed, as well as crunch variable names so as to minimize code and reduce file size. The minified file version provides the same functionality while reducing the bandwidth of network requests.

Examples

Before minified

      
// program to find the HCF or GCD of two integers

let hcf;
// take input
const number1 = prompt('Enter a first positive integer: ');
const number2 = prompt('Enter a second positive integer: ');

// looping from 1 to number1 and number2
for (let i = 1; i <= number1 && i <= number2; i++) {

    // check if is factor of both integers
    if( number1 % i == 0 && number2 % i == 0) {
        hcf = i;
    }
}

// display the hcf
console.log(`HCF of ${number1} and ${number2} is ${hcf}.`);
      
    

After minified

      
let hcf;const number1=prompt('Enter a first positive integer: ');const number2=prompt('Enter a second positive integer: ');for(let i=1;i<=number1&&i<=number2;i++){if(number1%i==0&&number2%i==0){hcf=i}}console.log(`HCF of ${number1} and ${number2} is ${hcf}.`);