ForHosting KIT · Developer Utilities

Minify JavaScript whitespace and measure the size reduction

This JavaScript whitespace minifier removes line comments, block comments, and formatting space that the runtime does not need.

● BetaFree · in your browser
Use it from WebAPIEmailTelegramApp soon

It keeps strings, template literals, regular-expression literals, operators, and identifier boundaries intact, while retaining line breaks where JavaScript automatic semicolon insertion can affect meaning. The result includes the compact source, original and minified UTF-8 byte counts, and the percentage saved. It is useful when you want predictable source compaction without identifier renaming, code rewriting, dependency installation, network access, or a complete bundling pipeline.

Compact source without rewriting the program

This capability focuses on one narrow job: removing comments and collapsing insignificant whitespace. It does not rename variables, fold constants, reorder expressions, alter property names, or transform modern syntax into an older language version. That limited scope makes the result easier to inspect and compare with the original. Send JavaScript in the javascript field, or use the accepted code or text alias, and receive compact JavaScript plus exact UTF-8 byte measurements. The scanner recognizes quoted strings, template literals, and regular-expression literals before it considers comment markers, so text such as a URL inside a string or a slash inside a regular expression is retained as program data. Spaces are reinserted only when adjacent tokens would otherwise merge into a different token. For example, two identifiers remain separated, while formatting around commas, braces, and most operators disappears. This is source compaction rather than obfuscation: names and program structure remain recognizable, and no hidden network service or nondeterministic model participates in the result.

Preserve JavaScript token and line-break semantics

Whitespace in JavaScript is often optional, but it is not universally meaningless. Joining two identifier characters can create a new name; joining two plus signs can create an increment operator; and removing a newline after return, throw, break, continue, or yield can change how automatic semicolon insertion interprets a statement. The minifier therefore tokenizes the input and makes boundary decisions between tokens instead of applying a global regular expression. It preserves significant line breaks for these automatic-semicolon-insertion cases and keeps potentially ambiguous operators apart. Comments are recognized only while the scanner is outside strings, template literals, and regular-expression literals. Delimiters are checked during the same pass: closing parentheses, square brackets, or braces must match the most recent opening delimiter. An unmatched or incorrectly nested delimiter produces an invalid-input error rather than suspicious output. Unterminated comments, strings, template literals, and regular expressions also fail clearly. This validation is deliberately structural rather than a full JavaScript parser, so the tool is best suited to syntactically valid source that needs conservative whitespace compaction.

Measure savings and integrate the deterministic result

The response reports original_bytes and minified_bytes using UTF-8 encoding, which is the relevant measurement for files transferred over HTTP or stored as ordinary web assets. It also reports reduction_percent rounded to two decimal places, making before-and-after checks simple in scripts, dashboards, or release notes. Because the algorithm is deterministic, the same input always returns the same output and byte counts. A build pipeline can submit generated source, write the returned javascript field to its artifact directory, and enforce a minimum reduction without installing a minifier package. A documentation system can compact inline examples while retaining meaningful tokens, and a lightweight deployment process can reduce hand-written utility scripts without introducing bundling or identifier mangling. The capability charges $0.002 per API request, while the browser execution path can use the same pure implementation. For production deployment, run the resulting program’s own tests as you would after any source-processing step. This tool protects lexical boundaries and delimiter balance, but tests remain the strongest confirmation for code that depends on unusual grammar contexts or host-specific behavior.

Compact a generated browser asset

Remove comments and formatting from generated JavaScript before publishing it, while keeping identifiers readable for diagnostics.

Shrink standalone utility scripts

Reduce the transfer size of a small script without adopting a bundler, variable mangler, or dependency-heavy build stage.

Track source-size savings

Record original bytes, minified bytes, and the percentage reduction in a release report or automated quality check.

What does the capability remove?

It removes line comments, block comments, and whitespace that is not needed to keep JavaScript tokens and selected automatic-semicolon-insertion boundaries separate.

Does it rename variables or change expressions?

No. It performs conservative lexical compaction only; it does not mangle names, fold constants, reorder code, or transpile syntax.

How is the size reduction calculated?

Both sizes are measured as UTF-8 bytes. The percentage is the byte difference divided by the original byte count, rounded to two decimal places.

What happens when delimiters are unbalanced?

The request fails with an invalid-input error when parentheses, square brackets, or braces are unmatched or incorrectly nested.

Are comment-like characters inside strings removed?

No. Quoted strings, template literals, and regular-expression literals are scanned as literals, so their internal slash characters are retained.

What does an API request cost?

Each API request costs $0.002. Failed validation requests are reported as errors rather than producing minified output.

Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.

POSThttps://api.kit.forhosting.com/dev2/minify-js

Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.

curl -X POST https://api.kit.forhosting.com/dev2/minify-js \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"javascript":"function add(a, b) {\n  // Return the sum\n  return a + b;\n}\n"}'
{
  "javascript": "function add(a, b) {\n  // Return the sum\n  return a + b;\n}\n"
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "dev2.minify_js",
  "status": "queued",
  "_links": {
    "result": "/tasks/tsk_…/result"
  }
}

The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

Read the full KIT documentation →