JavaScriptNew

JavaScript Minifier that Keeps Variable Names

Strip comments and whitespace without renaming variables

100% client-side — your data never leaves your browserNo data stored or uploadedFree for lifetime · No signup

What is a JS minifier?

A JavaScript minifier removes comments, collapses whitespace, and tightens the spacing around operators and punctuation so the script parses to the exact same behavior in far fewer bytes. For a script that runs on every page load, shaving even a few hundred bytes adds up across thousands of visits — and unlike CSS, unminified JS also carries readable variable names and comments that reveal implementation details you may not want shipped verbatim.

This tool does a lightweight, regex-based whitespace-and-comment strip in your browser. It does not rename variables or perform dead-code elimination the way a real compressor like Terser does — it's aimed at quick, dependency-free cleanup of a snippet, not replacing your build pipeline.

When to use it

Use it for inline `<script>` blocks, bookmarklets, small utility scripts served outside a bundler, or userscripts where pulling in a full build toolchain isn't worth it. It's also handy for quickly estimating how much of a file's size is just formatting versus actual logic.

For anything that ships to production as part of an app — a React/Vue/Svelte bundle, a Node package — rely on your bundler's minifier (Terser, esbuild, SWC). Those tools parse the AST and can safely rename local variables and remove unreachable branches; a regex-based pass like this one can't do that safely because it doesn't understand JS syntax, only text patterns.

Example

Input:

function greet(name) { // Say hello console.log("Hello " + name); }

Output: function greet(name){console.log("Hello "+name);} — the comment is removed, newlines are collapsed, and spacing around operators and braces is tightened, without changing what the function does.

How to use the JavaScript Minifier that Keeps Variable Names tool

  1. 1

    Paste your JavaScript

    Drop a script or function into the input panel.

  2. 2

    Click Minify

    Comments and non-essential whitespace are stripped in one pass.

  3. 3

    Check the savings

    Byte counts below the output show how much size was cut.

  4. 4

    Copy or share

    Copy the result, or copy a permalink that restores your input for anyone who opens it.

Frequently asked questions

Is my code uploaded anywhere?

No. The transform runs entirely in your browser — nothing you paste is sent to a server.

Does this rename variables like Terser does?

No. This is a whitespace-and-comment stripper, not a full compressor — it won't shorten identifiers, inline constants, or eliminate dead code. For that, use a real bundler minifier as part of your build.

Can this break my code?

It's regex-based rather than AST-based, so unusual syntax — regex literals containing `//`, template literals spanning multiple lines, ASI edge cases — can occasionally be minified incorrectly. Test the output before shipping it, and prefer a proper build step for production bundles.

What about CSS and HTML?

See the CSS Minifier and HTML Minifier tools for the same approach applied to stylesheets and markup.

Related on TechLogHub

Get the next tool before you need it

One email a week: new and trending developer tools, fresh comparisons, and what shipped. Unsubscribe in one click.