Skip to main content

    JavaScript Minifier

    Minify JavaScript online, strip comments and whitespace to reduce bundle size.

    Free to use. Runs in your browser.

    Paste JavaScript and click Minify to strip whitespace and remove comments. Typical size reduction is 30 to 60%.

    Use it for small scripts and quick deploy copies when a full build step is not available.

    Input JavaScript

    Minified Output

    Why Minify JavaScript?

    JavaScript is usually the biggest bottleneck in web performance. It has to be downloaded, parsed, compiled, and executed, all before your page becomes interactive. Every kilobyte counts. Minification strips the parts humans need (comments, indentation, blank lines) while keeping everything the browser needs.

    A typical JavaScript file shrinks 30-60% after minification. That's not just faster downloads, it's faster parsing too. V8 (Chrome's JS engine) parses minified code faster because there's less text to process. For mobile users on slow connections, the difference between 200KB and 100KB of JS can mean seconds of load time.

    This tool handles comment removal, whitespace collapsing, and basic operator spacing. For production use, build tools like Terser, esbuild, or SWC can also handle dead code elimination, tree shaking, and variable mangling.

    What Minification Removes

    ElementBeforeAfterSavings
    Comments// Calculate total /* Multi-line */(removed)10-30% of file typically
    WhitespaceIndentation, blank linesCollapsed to minimum15-25% of file
    Line breaksOne statement per lineEverything on fewer lines5-10% of file
    Variable names*calculateTotalPriceaSignificant for large files
    Dead code*Unreachable branches(removed)Varies widely

    What this means for you: Items marked with * require parser-aware minifiers such as Terser or esbuild. This online tool handles comments and whitespace, the quick wins that do not risk changing behaviour. Use it for one-off jobs; use build tools for production.

    JavaScript Minifiers in Build Pipelines

    ToolTypical roleNotesCommon context
    TerserParser-aware minificationCan mangle names, drop dead code, and simplify expressionsWebpack and Vite production builds
    esbuildBundling and minificationUsed when build speed matters and output size is still compactVite and CI pipelines
    SWCCompile and minifyRust-based compiler used by several JavaScript frameworksNext.js and transpilation-heavy projects
    UglifyJSLegacy minificationMostly useful for older ES5 projectsOlder build chains
    Closure CompilerTyped optimisationWorks well when code follows its annotation and module expectationsSpecialised large codebases

    Real-World Size Savings

    LibraryOriginalMinifiedMinified + Gzip
    jQuery 3.7282 KB87 KB (69%)30 KB
    React 18140 KB45 KB (68%)14 KB
    Lodash544 KB71 KB (87%)25 KB
    Three.js1.2 MB650 KB (46%)170 KB
    Typical app bundle500 KB200 KB (60%)65 KB

    Full parser-based minification with variable mangling (the production builds shown above) cuts 50-70%; stripping whitespace and comments alone, which is what this tool does, typically cuts 30-60%. Add Gzip/Brotli compression (which your server should already enable) and you're typically looking at 85-90% total reduction. That 500 KB bundle becomes 65 KB over the wire.

    Worked Example: Trimming an Inline Script

    Aisha maintains a static pricing page with a small inline script that toggles monthly and yearly prices. There is no bundler because the page is a single HTML file.

    1. Keep the readable script

    She keeps a readable copy with comments in the source file so future pricing changes are easy to review.

    2. Minify the deploy copy

    The minifier removes comments and spacing from the small script before she places it into the published HTML.

    3. Test click behaviour

    She clicks the monthly and yearly tabs, checks the displayed prices, and confirms that keyboard focus still moves correctly.

    4. Avoid editing output

    If the script needs another change, she edits the readable source and minifies again. She does not edit the compressed output directly.

    Minification Risks to Watch

    RiskWhy it happensHow to reduce it
    Regex mistaken for commentsSimple text minifiers can misread slashesReview code with regex literals after minifying
    Template literal changesBacktick strings can contain meaningful spaces and newlinesCheck generated strings and HTML fragments
    Missing source mapsOne-off minifiers do not map output back to sourceUse a build tool when production debugging matters
    Inline event handlersSmall snippets can rely on surrounding HTMLTest the full page, not only the script text
    Already compressed bundlesSome files are already minified by a build stepCheck before and after byte counts before replacing files

    Safe JavaScript Minification Checklist

    • Keep the readable source. The minified output is for delivery, not editing.
    • Run behaviour checks. Click UI controls, submit forms, and inspect console errors after using the output.
    • Use build tools for applications. Bundled apps need source maps, module handling, and parser-aware transforms.
    • Avoid minifying TypeScript directly. Compile TypeScript to JavaScript first, then minify the JavaScript output.
    • Do not minify secrets into client code. If a token appears in browser JavaScript, minification does not protect it.

    One-Off Minifier or Build Tool?

    Use the right level of tooling for the script. Small snippets and full applications have different needs.

    ScenarioGood fitWhy
    Small inline scriptOne-off minifierYou only need to trim comments and whitespace
    Static page without a build stepOne-off minifierA deploy copy can be smaller without changing your source file
    React, Vue, or app bundleBuild toolModules, source maps, tree shaking, and syntax transforms need a pipeline
    TypeScript projectBuild toolTypeScript must be compiled before JavaScript is minified

    Related Tools

    How to use this tool

    1

    Paste your JavaScript into the input area

    2

    Click Minify JavaScript to compress

    3

    Copy the result or download as a .min.js file

    Common uses

    • Reducing JavaScript file size for production
    • Stripping comments from code before deployment
    • Quick minification for inline scripts
    • Comparing file sizes before and after compression

    Share this tool

    Frequently Asked Questions

    What does JavaScript minification do?
    It removes comments, whitespace, line breaks, and unnecessary characters from your JavaScript code. The result is functionally identical code that's 30-60% smaller. Smaller files download faster, parse faster, and reduce bandwidth costs.
    Will minification break my code?
    Basic minification (comments and whitespace removal) is safe. Advanced minification (variable renaming, dead code removal) requires AST-based tools and proper testing. This tool handles the safe basics, use Terser or esbuild for production builds.
    Is my code sent to a server?
    No. All minification happens in your browser using JavaScript regex operations. Nothing is uploaded, stored, or transmitted. Safe for proprietary code.
    How much will my file shrink?
    Typically 30-60% depending on how much whitespace and comments your code contains. Well-commented code with generous formatting saves more. Already-compact code saves less. The tool shows exact before/after byte sizes.
    Should I minify in development?
    No, work with readable code during development. Only minify for production. Your build tool (Vite, webpack, esbuild) should handle minification automatically as part of the production build. Source maps let you debug production code in its readable form.
    What's the difference between minification and bundling?
    Minification shrinks individual files. Bundling combines multiple files into one (fewer HTTP requests). Tree shaking removes unused exports. Modern build tools do all three. This tool only does minification, for the full pipeline, use a build tool.
    What about source maps?
    Source maps connect minified code back to the original source for debugging. They're generated by build tools alongside the minified output. This online tool doesn't generate source maps, it's for quick one-off minification, not production pipelines.
    Does minification affect SEO?
    Indirectly, yes. Google uses page load speed as a ranking factor via Core Web Vitals. Smaller JavaScript files mean faster Time to Interactive (TTI) and lower Total Blocking Time (TBT). For content-heavy pages, reducing JS size directly improves SEO metrics.
    What is Terser and when should I use it?
    Terser is a JavaScript minifier used by many build pipelines. It parses your code into an Abstract Syntax Tree (AST), then can rename variables, remove dead code, and simplify expressions. Use it through a build tool when you need production-grade bundle minification.
    Can I minify ES6+ and TypeScript?
    This tool handles JavaScript syntax. TypeScript needs to be compiled to JavaScript first. For ES6+ features like arrow functions and template literals, the tool preserves them. Terser and esbuild handle current JavaScript syntax natively.
    What's the difference between Terser and esbuild?
    Terser is written in JavaScript, slower but produces slightly smaller output. esbuild is written in Go, 10-100x faster but slightly less aggressive compression. For most projects, esbuild's speed advantage outweighs the 1-2% size difference.
    How do I minify automatically in my build?
    Vite uses esbuild for minification by default. Webpack uses Terser via TerserPlugin. Next.js handles it automatically. Most current frameworks minify JavaScript as part of their production build with little configuration.
    Does this rename variables?
    No. This page focuses on comments and whitespace. Variable renaming needs a parser-aware minifier so local names can be shortened without changing scope or breaking references.
    Can I minify a single inline script?
    Yes. Paste just the JavaScript from inside a script tag, minify it, then place the result back inside the tag. Test the page afterwards because inline scripts often depend on surrounding markup.
    What should I do before minifying production code?
    Run your tests on the readable source, keep that source under version control, and minify only the deploy copy. If you need source maps, use a build tool rather than a one-off minifier.
    Why are source maps useful?
    A source map connects minified output back to the original files. Browser DevTools can show readable source while the site still ships smaller JavaScript to visitors.

    Results are for general informational purposes only and should be checked before use. They are not professional advice. See our Disclaimer and Terms of Service.