Not every script lives inside a project. Sometimes the whole job is one small standalone file: a bookmarklet-sized helper you keep in your browser toolbar, a single script that powers one page, or an embed snippet you hand to someone else to paste into their site. The code works, but it carries your comments, your blank lines and your generous spacing, and all of that is weight nobody needs in the shipped copy.

The standard answer, setting up a bundler or a build pipeline, is heavier than the job itself. Installing tooling, writing a config file and maintaining both just to compress one file is effort spent in the wrong place. This guide shows the lighter route: paste the script into the free JavaScript Minifier on Ovatly, minify it in one pass, and keep your readable original as the version you continue to edit.

Contents

  • Quick answer
  • When a build step is heavier than the job
  • What the minifier removes, and what it refuses to touch
  • How to minify a small script, step by step
  • Worked example: comments out, strings untouched
  • Limitations and alternatives
  • Common mistakes
  • FAQs
  • Conclusion

Quick answer

Paste your JavaScript into the JavaScript Minifier, press Minify JavaScript, and check the size report to see the saving. Then copy or download the minified code and ship that copy, while keeping your original readable file as the source you edit. The tool removes comments and unnecessary whitespace, tokenizes the code first so strings and regular expressions are never mistaken for comments, and runs entirely in your browser.

When a build step is heavier than the job

A build pipeline earns its keep when a project has many files, modules to combine, and a release process that repeats. A single script has none of that. There is one file, it changes occasionally, and the only transformation you want is the removal of comments and spare whitespace before the file goes out.

That is exactly the shape of job a paste-in tool fits. There is nothing to install and nothing to configure: the script goes in, the minified copy comes out, and the size report tells you what the pass saved. For a bookmarklet, a one-page script or an embed snippet, that is the whole workflow, and it stays the whole workflow for as long as the script stays small and standalone.

The boundary is worth naming honestly. One file, or a few files, minified by hand now and then: the paste-in route is fine. A project that keeps growing, with new files arriving and releases happening often, earns a real build step, because repeating a manual pass across many files is where mistakes and forgotten files creep in.

What the minifier removes, and what it refuses to touch

The minifier removes two things: comments, and whitespace the code does not need. Everything else about your program stays as written.

The careful part is deciding what counts as a comment. A naive find-and-replace would happily delete everything after a // anywhere on a line, including the // inside a URL stored in a string. This tool tokenizes the code first, which means it reads the script the way a parser would, telling strings, template literals and regular expressions apart from actual code. Text inside those constructs is data, not commentary, and it is never mistaken for a comment or stripped.

Two protections follow from that. Template literals are preserved verbatim, including the expressions inside them, so a template is never reshaped. And newlines that JavaScript's automatic semicolon insertion depends on are kept, because removing them could change what the code does. If the tokenizer meets something it cannot read safely, such as an unterminated string, template literal, block comment or regular expression, it reports an error instead of silently mangling the output.

Just as clearly, the tool does not shorten variable names, remove dead code or bundle modules. It is a whitespace and comment minifier, not an optimizing compiler, and the worked example below shows exactly that scope.

How to minify a small script, step by step

  1. Open the JavaScript Minifier and paste your JavaScript into the input box.
  2. Press Minify JavaScript.
  3. Check the size report to see the saving.
  4. Copy or download the minified code, and ship that copy. Keep the readable original as the file you edit.

Worked example: comments out, strings untouched

Here is a two-line script with a comment and a string that contains //:

const url = "https://example.com//not-a-comment"; // real comment
const x = 1;

Minified, it comes back as:

const url="https://example.com//not-a-comment";const x=1;

Look at what survived and what did not. The trailing // real comment is gone, and so is the spacing around the assignments. But the // inside the string is untouched, because it is data, not a comment: deleting it would have broken the URL. The statement newline between the two lines is preserved in effect through the semicolons, so the minified copy runs exactly as the original did. That is the whole character of the tool: aggressive about presentation, conservative about meaning.

Limitations and alternatives

The honest limit is scope. Because the minifier never rewrites your program, the saving is smaller than what an optimizing tool achieves. Terser, the minifier commonly used in build pipelines, also renames variables, folds constants and removes dead code, which is why its output shrinks further. If your script is large or part of a real project, that pipeline route goes further and is worth its setup cost.

The tool also works on plain JavaScript only. JSX and TypeScript syntax need a real parser first, so paste plain JavaScript. One rare tokenizer ambiguity is worth knowing: a regex literal appearing right after the closing brace of a block is treated as division, a corner every lightweight tokenizer has to resolve one way.

Finally, minification is a one-way presentation change. The minified copy is for shipping, not for editing, which is why the workflow keeps the readable original as your source.

Common mistakes

  • Editing the minified copy. Fixes made in the minified file vanish the next time you minify the original. Always edit the readable source, then minify again.
  • Expecting an optimizing compiler. If you were hoping for shorter variable names or dead code removal, this tool will disappoint you on purpose. It removes comments and whitespace only.
  • Skipping a test run. The tokenizer is conservative, but the entry advice stands: run your test suite, or at least click through the page, after minifying anything important.
  • Pasting JSX or TypeScript. Neither is supported. Convert to plain JavaScript first, or use a parser-based tool.
  • Setting up a pipeline anyway. For one small script, the config and maintenance cost more time than the manual pass ever will. Save the build step for the project that actually grows.

FAQs

Is the minified output safe to run? The tokenizer is conservative: it only removes comments and whitespace that cannot change meaning, and preserves statement newlines so automatic semicolon insertion behaves as before. Still, run your test suite after minifying anything important.

Why is the saving smaller than terser? Terser also renames variables, folds constants and removes dead code. This tool deliberately avoids rewriting your program; it just removes comments and spare whitespace.

Does it support JSX or TypeScript? No. Paste plain JavaScript. JSX and TypeScript syntax need a real parser first.

What happens to template literals when I minify? They are preserved verbatim, including the expressions inside them, so they are never reshaped.

Is my code uploaded anywhere? No. The minifier runs in your browser, so your script never leaves your device.

Conclusion

A small standalone script deserves a small standalone workflow: paste it into the JavaScript Minifier, check the size report, ship the minified copy, and keep the readable original as the file you edit. When the day comes that you need the compressed code readable again, the companion guide on formatting JavaScript after copying it from a browser console covers the reverse trip, and the rest of this series lives in the Developer Tools guides archive.