⚑ Free JavaScript Minifier

JavaScript Minifier

Shrink your JavaScript by removing comments and collapsing whitespace β€” safely protecting your strings, template literals and regular expressions. Paste your code, choose your options and copy the smaller result. 100% in your browser β€” nothing is uploaded or stored.

ℹ️
Safe, conservative minification: This tool removes comments and extra whitespace without renaming variables or restructuring code, so it never changes how your script behaves. For aggressive minification (variable mangling, dead-code removal), use a build-step tool like Terser. Everything here runs locally on your device.
Input JavaScript
Minified Output

πŸ”’ Everything runs in your browser. Your input is never uploaded, logged or stored.

The JavaScript Minifier shrinks your scripts by removing comments and collapsing whitespace, while carefully protecting your strings, template literals and regular expressions so the code keeps working exactly as before. Smaller scripts download and parse faster, which helps page speed and Core Web Vitals β€” factors that affect both the visitor experience and search performance.

It is part of the Performance & Code Tools group in our free SEO Toolkit, alongside the HTML Minifier and CSS Minifier. To make minified code readable again, use the Code Beautifier, and estimate total page weight with the Page Size Calculator, and embed images inline with the Base64 Image Encoder. This is a safe, conservative minifier β€” it does not rename variables β€” so for aggressive optimisation a build-step tool is the right choice. Everything runs in your browser β€” your input is never uploaded or stored.

⚑
Instant
100%
Free Forever
0
Data Stored
99.9%
Uptime
β€” Features β€”

Smaller Scripts, Safely

Minify JavaScript without breaking your logic.

Strip Comments

Removes line and block comments that the engine ignores.

Collapse Whitespace

Trims indentation and extra spaces between statements.

Literal-Safe

Protects strings, template literals and regular expressions.

Live Savings

See the byte size before and after, with the percentage saved.

β€” How It Works β€”

Minify in Three Steps

Paste, choose options, copy the smaller file.

1

Paste JavaScript

Drop in a function, a module or a whole file.

2

Pick Options

Choose what to remove.

3

See Savings

Compare original and minified sizes.

4

Copy or Download

Use the minified script on your site.

β€” Example β€”

Before and After

Comments and indentation gone; logic untouched.

Before
// add two numbers
function add(a, b) {
    return a + b;
}
After
function add(a, b) {
return a + b;
}

What Is JavaScript Minification?

JavaScript minification reduces the size of a script by removing characters that are not needed to run it β€” comments, indentation, line breaks and surplus spaces. The behaviour is unchanged, but the file is smaller, so it downloads and parses faster. This tool performs safe, conservative minification: it strips comments and collapses whitespace while protecting the parts of your code where spacing matters. It is part of the Performance & Code Tools group.

Conservative vs Aggressive Minification

There are two levels of JavaScript minification. Conservative minification, which this tool does, removes comments and whitespace without changing any names or structure, so it is safe to apply to any valid script. Aggressive minification, performed by build tools such as Terser, also renames variables, drops dead code and rewrites expressions for maximum savings. Aggressive tools squeeze out more bytes but need a build step and careful testing; this tool gives you quick, reliable gains with zero risk to your logic.

What Is Protected

ProtectedWhy
StringsSpaces inside quotes are part of your data
Template literalsBacktick strings keep their exact formatting
Regular expressionsSpaces and slashes inside a regex are significant
Division operatorsA slash used for division is never mistaken for a regex

Why Minify JavaScript?

⚑

Faster Loads

Smaller scripts download and start running sooner.

πŸ“Š

Better Vitals

Lighter scripts help your Core Web Vitals scores.

πŸ“‰

Less Bandwidth

Fewer bytes served reduces data and hosting costs.

πŸ“±

Mobile Wins

Speed gains matter most on slower connections.

What This Minifier Does

  • Removes single-line and block comments
  • Collapses indentation and repeated spaces
  • Removes blank lines to tighten the code
  • Protects strings, template literals and regular expressions
  • Distinguishes division from regular expressions correctly
  • Shows byte sizes and percentage saved, with copy and download

How to Use the JavaScript Minifier

  1. Paste your scriptEnter a function or a whole file.
  2. Choose your optionsDecide what to remove.
  3. Review the savingsCheck the size comparison.
  4. Copy or downloadUse the minified script on your site.

Technical Notes

This tool is designed to be safe. It only removes comments and whitespace outside of strings, template literals and regular expressions, and it does not rename anything. For ordinary, valid JavaScript the behaviour is unchanged. As with any change to production code, test the minified output before deploying.

No, and that is deliberate. Renaming variables and rewriting code can produce much smaller files but requires a full parser and careful testing. This tool focuses on safe comment and whitespace removal so you get quick gains with no risk. For maximum compression, use a build-step tool such as Terser in your pipeline.

The tool scans your code character by character and tracks the previous meaningful token. A slash that follows a value or closing bracket is treated as division, while a slash in a position where an expression begins is treated as the start of a regular expression. This avoids the classic mistakes that naive minifiers make.

No. Minification runs locally in your browser with JavaScript. Nothing you paste is uploaded, logged or stored, so the tool is safe for proprietary scripts, unreleased features and confidential client work.

Common Use Cases

⚑

Speed Optimisation

Trim script weight to improve load times.

πŸ’»

Snippets

Compress small scripts and inline code blocks.

πŸ“¦

Embeds

Compact JavaScript shipped with widgets.

πŸŽ“

Learning

See how comments and whitespace add to file size.

Use the JavaScript Minifier with these tools from the SEO Toolkit: compress markup with the HTML Minifier, shrink stylesheets with the CSS Minifier, reformat minified code with the Code Beautifier, estimate weight with the Page Size Calculator, embed images inline with the Base64 Image Encoder, and build head tags with the Meta Tag Generator.

β€” Who It's For β€”

Built for Everyone

Anyone who wants lighter, faster scripts.

πŸ’» Web Developers πŸ“ˆ SEO Specialists ⚑ Performance Engineers 🎨 Front-End Designers 🏒 Agencies πŸš€ Site Owners πŸ”Œ Plugin Authors πŸŽ“ Students & Learners
β€” FAQ β€”

Frequently Asked Questions

Everything about minifying JavaScript.

It reduces the size of your script by removing comments and collapsing whitespace, while protecting strings, template literals and regular expressions so the behaviour is unchanged. You paste your code, pick your options and copy the smaller, minified output for use on your site.

Yes, completely. There is no cost, no sign-up and no limit on how much code you minify. The tool runs entirely in your browser, so there are no server costs and nothing to pay for.

It is designed not to. The tool removes only comments and whitespace outside of strings, template literals and regular expressions, and it never renames anything, so valid scripts behave the same. As with any production change, test the output before you deploy it.

No, and that is intentional. Variable renaming and code rewriting need a full parser and careful testing. This tool focuses on safe comment and whitespace removal so you get quick gains with no risk. For maximum compression, use a build-step tool such as Terser.

Yes. Minification happens locally in your browser with JavaScript. Nothing you paste is uploaded, logged or stored, which makes the tool safe for proprietary scripts, unreleased features and confidential client work.

The tool scans your code character by character, identifying strings, template literals and regular expressions, and leaves their contents untouched. Only the code outside these literals has its whitespace collapsed, so a space inside a string or a regex is always preserved.

It tracks the previous meaningful token. A slash after a value, variable or closing bracket is treated as division, while a slash where an expression can start is treated as the beginning of a regular expression. This avoids the errors naive minifiers often make.

It depends on how many comments and how much indentation your code contains. Heavily commented, nicely formatted code can shrink noticeably, while compact code saves less. Because this tool does not rename variables, savings are smaller than an aggressive build tool but completely safe.

Minification removes comments and formatting, so it is not perfectly reversible, but you can reformat minified code into a clean, indented layout with the Code Beautifier. Always keep your original source in version control as the source of truth.

This tool is ideal for one-off files, snippets and learning. For a live site, minify automatically in your build process or via an optimisation plugin so every change is processed consistently. Use this tool for ad hoc scripts and to see the savings.

Yes. The minifier is fully responsive, so you can compress JavaScript from a phone or tablet. Pasting your code, toggling options, viewing the savings and copying the output all work the same as on desktop.

Minify Your JavaScript Now

Strip comments and whitespace safely to make your scripts lighter and your pages faster in seconds β€” free, private and instant in your browser.

⚑ Open the Minifier ← All Performance Tools