Developer tools

JavaScript Minifier

JavaScript Minifier

Safely minify JavaScript by removing comments and whitespace.

About this tool

About JavaScript Minifier

Shrink a script for an inline <script> tag, a bookmarklet, a code snippet in a CMS or a quick deploy without a build step. This minifier is deliberately conservative. It removes line and block comments, indentation, trailing spaces and blank lines, and the spaces next to punctuation such as braces, brackets, commas and equals signs. It reads the code as tokens, so text inside strings, template literals and regular expressions is copied exactly and a // inside a string is never treated as a comment. Each statement keeps its own line, which means automatic semicolon insertion works exactly as it did before and code without semicolons is safe. What it does not do: rename variables, inline functions, remove unused code or join lines. Those optimisations need a full parser such as esbuild or Terser in your build. Licence comments that begin with /*! are kept unless you turn that off, and the bytes saved are shown. It runs in your browser.

Built and maintained by Abhi JainUpdated

How to Minify JavaScript

  1. 1

    Paste or open code

    Paste JavaScript into the left pane or open a .js file.

  2. 2

    Choose licence handling

    Keep /*! licence */ comments is on by default; turn it off to strip every comment.

  3. 3

    Copy or download

    Copy the minified code or download it as a .min.js file.

JavaScript Minifier: questions and answers

Is this minifier safe for code without semicolons?

Yes. Line breaks between statements are kept, so automatic semicolon insertion behaves exactly as in the original file.

Does it rename variables or remove unused code?

No. It only removes comments and whitespace. Renaming and dead-code removal need a full JavaScript parser and are best done by a bundler such as esbuild or Terser.

Why keep /*! comments?

By convention, comments starting with /*! hold licence notices that many open-source licences require you to keep in distributed code.

Is my code uploaded?

No. Minification runs entirely in your browser.

More JavaScript Formatter presets