Pular para o conteúdo
POST AI agent ready /v1/minify/js

JavaScript Minify API - Remove Comments and Whitespace

Strips // line comments and /* */ block comments while respecting string and template-literal boundaries. Collapses whitespace and removes spaces around operators and punctuation, keeping a single space after keywords (return, typeof, function, await, etc.) to preserve semantics. No identifier mangling or tree-shaking; the output is valid, readable-ish JavaScript.

Parameters

stringrequired

JavaScript source to minify.

Code examples

curl -X POST https://api.botoi.com/v1/minify/js \
  -H "Content-Type: application/json" \
  -d '{"code":"function add(a, b) {\n  // sum two numbers\n  return a + b;\n}"}'

When to use this API

Minify user-submitted scripts at ingest

When users submit JavaScript snippets (for an analytics injector, a tag manager, or a custom widget), minify before storing. Cuts DB size and response payload.

Build-step minification for small projects

Projects that don't want a full Terser setup can run this endpoint to strip comments and whitespace. Not as aggressive as Terser/esbuild but zero-dependency.

Pre-flight before shipping inline scripts

Inline <script> blocks in HTML are often hand-written. Minify them before server rendering to reduce HTML bloat without losing source maps.

Frequently asked questions

Does this mangle identifiers?
No. Function and variable names are preserved. For full mangling run Terser or esbuild locally. This endpoint focuses on the safe transforms that survive unusual inputs without breaking.
Are source maps generated?
No. No source-map output. For production JS needing debuggability, use a proper bundler that emits .map files alongside the minified output.
Does it handle template literals safely?
Yes. String quotes and backticks are tracked, so comment-like sequences (`//`) inside strings are not stripped.
What about async/await and modern syntax?
Recognized as keywords and get a preserved trailing space. ES2020+ features (optional chaining, nullish coalescing) pass through unchanged.
Typical savings?
25-50% depending on comments and indentation. Full Terser runs typically reach 55-70% on the same input via identifier mangling.

Get your API key

Free tier includes 5 requests per minute with no credit card required. Upgrade for higher limits.