JS minifier

Minify your JS by removing all the unnecessary characters.

Rated 5 out of 5 (total ratings: 1)
JS minifier

JS minifier is a free tool that removes unnecessary characters from JavaScript and returns the compact code with its original and minified character counts.

Where does minification belong in a JavaScript deployment pipeline?

Minification usually belongs near the end of the deployment pipeline, after linting, testing, transpiling, and bundling are complete. Paste the production-ready code into the JS field, run the tool, and use the returned Minified JS as the compact version.

The operation reduces characters that are not required for execution, commonly including indentation, line breaks, comments, and some spaces. A minifier may also shorten or restructure code, although the exact transformations depend on its implementation. Minification is separate from bundling, tree shaking, and transpilation. It does not make newer JavaScript syntax compatible with older browsers.

For a one-time script or a small static site, an online minifier can fit into a manual pre-deploy check. Repeated builds are usually better handled by a project tool such as Terser, esbuild, Rollup, or a framework's production build command. That keeps output reproducible and can generate source maps alongside the minified bundle.

The work for this JS minifier is performed on the server. Your JavaScript travels to the server over HTTPS and is not stored. Even so, remove credentials, private tokens, and other secrets before submitting JavaScript to this JS minifier.

How should you interpret the returned character counts?

Use the JS characters and Minified JS characters counts to compare source length with minified length, not as an exact prediction of transferred bytes or page-load time. JS characters reports the original character count, while Minified JS characters reports the count after minification.

The counts use PHP's mb_strlen function, so they represent characters rather than the UTF-8 byte size of the file. An accented or non-Latin character may occupy more than one byte even though it is counted as one character. When serving minified JavaScript, HTTP compression such as Brotli or gzip can further reduce the transferred size, and repeated tokens often compress well.

For example, this readable source contains spacing and a comment:

Input: function total(price, tax) { /* invoice total */ return price + tax; }

A typical compact equivalent is:

Compact form: function total(price,tax){return price+tax;}

Spaces inside quoted values must remain part of the value:

Input: const city = "New York";

Compact form: const city="New York";

Character reduction alone does not show whether JavaScript behavior was preserved. Run the resulting script in the same environment and test the same user flows as the original.

What JavaScript syntax should you check before minifying?

Check for incomplete or ambiguous syntax before minifying, especially unmatched delimiters, unterminated literals, and code that depends on automatic semicolon insertion. A parser-based minifier commonly stops when it cannot parse the input, but this tool's documented result fields do not include a dedicated syntax-error report.

  • Strings and template literals: A missing closing quote, backtick, or template expression brace can prevent parsing.
  • Comments: An unclosed block comment can make the remainder of a file appear to be commented out.
  • Regular expressions: A missing slash or invalid flag may be reported as a syntax error.
  • Automatic semicolon insertion: A line break after return can affect meaning, a line terminator after throw is a syntax error, and a line break after break or continue can affect meaning when a label follows. Concatenating files without boundary semicolons can also create unexpected expressions.
  • Modern syntax: Optional chaining, private class fields, decorators, and other newer constructs require a parser that understands the relevant syntax.

JavaScript and JSON also have different grammar rules. Object-literal property names may be unquoted when their form is permitted by JavaScript grammar, such as an IdentifierName or numeric literal, and many trailing commas are valid in JavaScript, but JSON requires quoted property names and does not permit trailing commas. Use JSON validator & beautifier when the input is JSON rather than executable JavaScript.

Whitespace is context-sensitive. A space can often be removed around punctuation, but removing every space mechanically can merge identifiers, numbers, or operators. Unicode identifiers and Unicode characters inside strings are valid in JavaScript when used according to the language grammar, so a correct minifier must distinguish code from literal content.

Example result produced by the JS minifier tool

Pre-deploy checks for compact JavaScript

Keep the readable JavaScript source as the maintained version and treat minified JavaScript output as a deployment artifact. Editing minified JavaScript directly makes reviews, debugging, and future changes harder.

  1. Run the project's syntax checker, linter, and automated tests on the source.
  2. Complete any bundling or transpilation required for the target browsers or runtime.
  3. Minify the final JavaScript rather than each intermediate module separately.
  4. Compare the original and minified character counts, then save the returned code as a separate production file.
  5. Test startup, event handlers, network requests, dynamic imports, and error handling with the minified file.
  6. Regenerate deployment metadata that depends on the exact bytes of the final minified JavaScript file, including integrity values and cache revisions.
The JS minifier tool on biolink.page, showing its input form

Running an already-minified vendor file through another minifier is often not worth doing. The size change may be small, while another transformation can complicate support or licensing review. Minification is also usually unnecessary for JavaScript used only during local debugging. Likewise, prettifying JSON that only a machine reads adds whitespace without helping that machine, although readable formatting can still help during diagnosis.

Very large bundles may be more practical in a local build system, where memory limits, parser versions, source maps, and repeatable settings are under project control. If a page also ships separate CSS or HTML assets, CSS minifier and HTML minifier can handle those formats rather than treating all source as JavaScript.

Common questions about JavaScript minification

Can a minifier remove required license comments?

Some minifiers preserve comments beginning with /*! or comments containing recognized license markers, but preservation rules vary. Do not assume a required notice will remain unless you inspect the output or use a configured build tool. Keep any legally required notices in the distributed package or a separate license file as appropriate.

Can I minify JavaScript copied from an HTML script element?

You can minify the JavaScript itself, but remove the surrounding script tags before placing it in the JS field. Be careful with literal closing script sequences inside strings because an HTML parser can end an inline script before the JavaScript parser sees the rest. External .js files avoid that particular embedding issue.

Does minification change a Content Security Policy hash?

Yes. A CSP hash is calculated from exact script content, so removing one space or line break produces a different hash. Generate the CSP hash only after the final minified inline script has been finalized for deployment.

Will minified code run in browsers that reject the original syntax?

No. Minification does not provide backward compatibility by itself. Transpile unsupported syntax first, then minify the generated code and test it in the oldest browser or runtime your project supports.

Why are production stack traces harder to read after minification?

Minified files commonly place substantial code on one line and may use shortened identifiers, so stack locations are less descriptive. Keep the exact deployed artifact and generate source maps through the build system when production debugging requires a connection back to the readable source.

Similar tools

HTML minifier

Minify your HTML by removing all the unnecessary characters.

111
1
CSS minifier

Minify your CSS by removing all the unnecessary characters.

114
1

Popular tools