Developer Tools
JavaScript Minifier to Compress JS Online
Minifies JavaScript by removing comments and whitespace without breaking strings.
JS Minifier tool
Your minified JavaScript appears here
Paste code, fetch a script by URL or upload a file. Standard minification updates as you type.
About the JS Minifier
Every script on a page has to be downloaded, parsed and run, and the comments and indentation you wrote for yourself go along for the ride. Kwebby's JavaScript Minifier removes that extra text from code you paste, fetch from a URL or upload. It shows the size before and after, and gives you a compact version to copy or download. This guide explains what each mode does, what Standard mode keeps safe, and when a build tool is the better choice.
Key Takeaways
- Kwebby's JavaScript Minifier removes comments and extra whitespace. It keeps strings, template literals and regular expressions exactly as written.
- You can paste code, fetch a script from a URL, or upload a .js, .mjs or .ts file of up to 500KB.
- Standard mode runs in your browser as you type and does not rename variables. Fetch URL uses the Kwebby server to download the file, and AI Optimize sends your code to an AI model.
- Standard mode keeps a line break wherever code without semicolons depends on it, so the output parses the same way as your source.
- Original, Minified and Saved figures show your own result. Copy and Download give you
script.min.js. - Minifying makes code smaller, and it does not hide it. For production apps, Terser or your bundler shrinks code further.
What Is the Kwebby JavaScript Minifier?
Kwebby's JavaScript Minifier is a free online tool that shrinks JavaScript by removing comments, whitespace and line breaks. You put code in the Input JavaScript box and read the smaller version in the Minified Output box. It suits one-off scripts, snippets outside a build pipeline, and quick checks on how much of a file is formatting.
Minifying rewrites how the code is written and aims to leave what it does unchanged. Chrome's Lighthouse documentation defines it as removing whitespace and any code that is not necessary to create a smaller but perfectly valid file.
Key Features and How It Works
Three ways to load JavaScript
The tabs above the editor are Paste, Fetch URL and Upload File. Paste is the default. Fetch URL takes an address such as https://example.com/script.js, and the Fetch button asks the Kwebby server to download the file into the input box (up to 500KB). Upload File accepts .js, .mjs and .ts files of up to 500KB. Loading a file or a URL switches the tool to Standard mode.
Standard mode
Standard mode is the default and runs in your browser as you type or paste. It reads the code token by token and does these things:
- Deletes
/* block */comments and//line comments. Comments that start with/*!, which usually hold license text, are kept. - Removes indentation, blank lines and spaces that the code does not need, such as the spaces around operators, commas and brackets.
- Removes a line break when the code on either side cannot be read differently without it, for example after
{,,,;or=. - Keeps a line break where automatic semicolon insertion (ASI) depends on it, for example between
const a = 1andconst b = 2written without semicolons.
It copies strings, template literals and regular expressions unchanged, so "https://example.com" keeps its // and 'Hello, ' keeps its space. It also keeps the space in sign pairs such as a + +b. It does not rename variables, and it does not remove dead code.
AI Optimize mode
AI Optimize is a button next to Standard. When you click it, your code goes to a Kwebby endpoint, which passes it to an AI model through OpenRouter and returns the result. The AI is asked to shorten variable names, remove dead code and remove console.log calls. This step accepts up to 80KB of code, and very long results can be cut short, so keep large, private or customer-specific scripts to Standard mode. If the AI step fails, the tool shows an error and returns to Standard mode.
Removing console.log calls and dead code changes what the file does, so treat AI output as a code change. Compare it with your original and test it.
Original, Minified and Saved figures
When there is input, three boxes report the Original size, the Minified size and the Saved amount. Each box also shows a line count, and Saved adds the percentage reduction. These are the real figures for your file, which is more useful than a generic percentage.
Copy, download and Clear
The output box has a Copy button and a Download button that saves the result as script.min.js. Clear empties both boxes for the next script.
Why Minifying JavaScript Matters
Scripts cost time twice, once in the download and once when the browser parses them. Lighthouse notes that minifying JavaScript files can reduce payload sizes and script parse time. A smaller file helps most on slow connections and phones, where every kilobyte counts.
Minifying is also a small part of a bigger routine. Server compression shrinks the same file again in transit, and MDN's guide to HTTP compression says text compression can cut file size by up to 70 percent. You can test whether your server does this with the Gzip compression checker.
Minification is not a security measure. Cloudflare's explainer on minifying JavaScript separates it from obfuscation, which deliberately makes code hard to read. Anyone can run a beautifier over minified JavaScript.
How to Use the JavaScript Minifier
- Choose a tab. Pick Paste, Fetch URL or Upload File.
- Load your code. Paste into Input JavaScript, enter a script address and click Fetch, or choose a .js, .mjs or .ts file.
- Stay in Standard mode. The Minified Output box updates as the input changes.
- Read the numbers. Check Original, Minified and Saved.
- Try AI Optimize if you want a second version. Click AI Optimize, wait for the result, then compare it with the Standard output.
- Copy or download. Click Copy, or click Download to save
script.min.js. - Test the script. Run the minified file on a staging page and watch the browser console for errors.
- Clear. Click Clear before the next script.
Best Practices for Minifying JavaScript
Keep your readable source
Minified code is hard to debug. Store the readable file in your project and serve the minified copy. A beautifier can restore line breaks, but it cannot restore deleted comments or original variable names.
Know what Standard mode keeps
Standard mode keeps a line break wherever removing it could change how the code is read, so code without semicolons often keeps several lines. MDN's lexical grammar reference lists the rules for automatic semicolon insertion. If you want a single line, end your statements with semicolons in the source.
Test the output once
Standard mode only removes comments and whitespace, and it keeps strings, regular expressions and template literals as written. Run the minified file once on a staging page anyway, and treat AI Optimize output as a code change that needs a full test.
Use a build tool for applications
An online tool suits quick jobs. Terser, the minifier named in the Lighthouse documentation, parses your code, shortens names and can write source maps for debugging. Its README warns that its property mangling option will break code unless you know how it works, so even a build tool needs testing. Use Kwebby for one-off files and for seeing the size gain.
Common mistakes to avoid
- Overwriting your only readable copy.
- Shipping without running the script once.
- Treating minified code as hidden or protected.
- Pasting private code into the AI step.
Common Use Cases
- Scripts outside a build pipeline. Shrink a hand-written widget or tracking snippet.
- Embed snippets. Compress code that must fit in a CMS field or an email template.
- Speed audits. Clear an unminified JavaScript warning for a file you do not build yourself.
- Size checks. Fetch a public script by URL and see how much is whitespace.
- Teaching. Show students what the browser needs and what only people need.
Related Kwebby Tools
- CSS Minifier shrinks stylesheets the same way.
- HTML Compressor trims comments and whitespace from markup.
- Check Gzip Compression shows whether your server compresses scripts in transit.
- Page Speed Checker measures the page after you ship smaller files.
- Diff Checker compares the original and the AI Optimize output line by line.
- Free Developer Tools Online lists the other minifying, encoding and hashing tools on Kwebby.
Final Thoughts
Minifying JavaScript is a quick win for scripts that sit outside your build, as long as you test the result. Kwebby's JavaScript Minifier gives you three ways to load code, a safe Standard mode and an AI Optimize option, with clear size figures for each run. Paste a script, read the Saved number, then run the output on a staging page. After that, check server compression with the Gzip compression checker.
FAQ
Frequently asked questions
What does a JavaScript minifier do?
A JavaScript minifier removes characters the browser does not need, such as comments, line breaks and extra spaces. Some minifiers also rename variables and delete dead code. Kwebby's Standard mode does the first part, and AI Optimize is the mode aimed at the second.
How much smaller does minified JavaScript get?
It depends on how many comments and how much indentation your code has. A neatly formatted, heavily commented file shrinks more than one that is already compact. Kwebby's Saved box shows the exact reduction for your file.
Does minifying JavaScript help SEO?
Only indirectly. A smaller script downloads and parses faster, which helps visitors on slow connections, and speed is one part of a good page experience. It will not lift rankings alone, so treat it as speed housekeeping.
Can minified JavaScript be reversed?
You can restore line breaks and indentation with a beautifier. Deleted comments are gone, and if variables were renamed the original names are gone too unless you kept a source map. Always keep your original file.
What is the difference between minification and obfuscation?
Minification makes code smaller. Obfuscation makes code hard to read on purpose, to protect logic from copying. Minified code is still easy to reformat, so do not rely on it for protection.
Can the Kwebby JavaScript Minifier break my code?
Standard mode is built to avoid that. It only removes comments and whitespace, keeps strings, template literals and regular expressions unchanged, and keeps the line breaks that code without semicolons needs. AI Optimize rewrites code, so it can change behavior. Test the output either way, and use a parsing minifier such as Terser for production builds.
Kwebby builds software too
Need a website or app built?
Get 50% off your first project. The discount applies to your first fixed quote only. Kwebby has delivered 1,200+ projects on fixed quotes from $100.