Code Minifier & Beautifier
Squeeze it down, or open it back up
Minify or beautify HTML, CSS and JavaScript, with a size report and safe handling of strings, comments and regular expressions.
Code Minifier & Beautifier
Runs in your browser · nothing uploaded01 — How to use Code Minifier & Beautifier
02 — Getting good results
03 — Questions
No. Every transform runs in this browser tab. Nothing is sent to a server, which is the point for unreleased or proprietary code.
Because removing them is not safe without a full parse. JavaScript inserts semicolons automatically at certain line endings, so joining two lines can change a program's meaning rather than just its size. This tool keeps every line break and removes only what is provably redundant.
No. The source is tokenised before anything is removed, so string literals, template literals, regular expressions and comments are identified first. Whitespace inside a string is preserved, and a slash inside a regex is never mistaken for a comment.
No. The contents of pre, textarea, script and style are set aside before whitespace is collapsed and restored afterwards, because whitespace inside them is significant.
04 — More about Code Minifier & Beautifier
Why a safe minifier keeps line breaks
JavaScript does not require a semicolon at the end of every statement; the parser inserts them automatically under a set of rules known as automatic semicolon insertion. Most of the time this is invisible, but a few rules bite hard. The clearest is that a return, break, continue or throw followed by a line break gets a semicolon inserted immediately, regardless of what comes next — so a function whose return value sits on the following line returns undefined. A minifier that joins lines has to know whether joining them changes the parse, and answering that reliably means building the full syntax tree, which is what production tools like Terser do. This tool does not build one, so it does not join lines. The result compresses less than a build-step minifier and is correct for every input, which is the right trade for a paste-and-go utility.
Tokenising before transforming
Every naive minifier eventually corrupts something, and it is almost always because it used a regular expression to strip comments or collapse whitespace across the whole file at once. A URL containing // inside a string gets truncated as a comment. A regular expression containing /* swallows the rest of the file. A CSS content property loses the spaces it was displaying on purpose. The fix is to make one pass that classifies the source into code, strings, comments and regular expressions first, and only then apply transforms to the code spans. That is why the slash-disambiguation logic here looks at the previous meaningful character: after a value or a closing bracket a slash is division, and after an operator or keyword it starts a regular expression. Getting that single decision right is most of what separates a minifier that works from one that corrupts files occasionally.
61 more tools
where this came from.
Same shell, same shortcuts, same promise: nothing leaves your browser.