JavaScript Minifier

Shrink JavaScript by removing comments and whitespace, keeping the spaces and line breaks the code needs. Names are not renamed, so the result is safe to use as it is.

Processed on your device. Files are not uploaded

How to minify JavaScript

  1. Paste your JavaScript

    Paste or type it into the box, or press Try an example.

  2. Choose whether to keep license comments

    Comments that start with /*! are kept by default.

  3. Copy or download

    Save the output as a .min.js file for production.

Worked example

This is what JavaScript Minifier gives for its own sample values. Open the tool above and change anything to try your own.

JavaScript

import {readFile} from "fs/promises";const cache=new Map()
export async function load(path,{retries=3}={}){if(cache.has(path))return cache.get(path)
for(let i=0;i<retries;i++){try{const text=await readFile(path,"utf8");cache.set(path,text);return text}catch(err){if(i===retries-1)throw err}}}
// done
Keep /*! license */ comments
Yes

Minified

import{readFile}from"fs/promises";const cache=new Map()
export async function load(path,{retries=3}={}){if(cache.has(path))return cache.get(path)
for(let i=0;i<retries;i++){try{const text=await readFile(path,"utf8");cache.set(path,text);return text}catch(err){if(i===retries-1)throw err}}}

About JavaScript Minifier

Make JavaScript smaller by removing comments and whitespace. It keeps the spaces and line breaks the code relies on, so code without semicolons still works. Variable names are not shortened, which keeps the result predictable.

FAQs

Is it safe?

It only removes whitespace and comments, and it reads strings, templates and regular expressions properly, so they are left alone.

Does it rename variables?

No. A full minifier that renames variables saves more, but it needs a build step.

Can I read minified code again?

Use JavaScript Formatter.

Related tools