Many WordPress sites carry one small piece of custom JavaScript: a snippet added to a child theme, a little helper that wires up a menu or a form, a few dozen lines you wrote or copied once and now serve on every page. That file is usually readable, commented and nicely indented, because it was written for a person. Minifying that one file by hand is a reasonable job, and a paste-based tool is a reasonable way to do it.

This guide shows how to minify a single custom script with the free JavaScript Minifier on Ovatly. It is equally clear about the boundary: this is a manual workflow for one small file you control, not a site-wide solution. If your site loads JavaScript from many files, the last section points at the route that actually fits.

Contents

  • Quick answer
  • Which WordPress scripts this suits, and which it does not
  • What the minifier actually removes
  • How to minify a custom script, step by step
  • Worked example: a comment removed, a string left alone
  • Limitations and alternatives
  • Common mistakes
  • FAQs
  • Conclusion

Quick answer

Find the custom script, save an untouched backup copy of it, and paste the code into the JavaScript Minifier. Press Minify JavaScript, check the size report to see the saving, then copy or download the result and replace the file's contents with it. Finally, test the pages that use the script. The tool removes comments and unnecessary whitespace only, and everything runs in your browser; nothing is uploaded. It does not integrate with WordPress, has no plugin, and never touches PHP.

Which WordPress scripts this suits, and which it does not

The workflow fits a script with three properties: it is small, it is yours, and you can put the original back if anything looks wrong. A customization snippet in a child theme is the classic case. So is a single hand-written file you added for one interaction, where the readable version lives in your theme and the minified version is what you want the site to serve.

It does not fit plugin files. Plugins update themselves, and an update will overwrite your minified copy with the vendor's original, so the work disappears and the file you edited is no longer the file you think it is. It also does not fit the long tail of scripts a typical site loads from themes, plugins and WordPress itself. Pasting file after file into a browser tool is slow, error-prone and impossible to repeat consistently the next time something changes. That scale of job belongs to a pipeline, covered under Limitations below.

What the minifier actually removes

The tool removes comments and unnecessary whitespace, and nothing else. It does not shorten variable names, remove dead code or bundle modules together. That restraint is deliberate: it never rewrites your program, so the minified file is the same program with the packaging taken off.

Getting even that much right takes care, because JavaScript is full of text that looks removable but is not. The minifier tokenizes the code first, so text inside strings, template literals and regular expressions is never mistaken for a comment. Template literals are preserved verbatim, including the expressions inside them. Newlines that JavaScript's automatic semicolon insertion depends on are kept, so statements still end where they ended before. If the code contains an unterminated string, template literal, block comment or regular expression, the tool reports an error instead of silently mangling the output.

How to minify a custom script, step by step

  1. Find the script and confirm it is one you control and can safely edit, not a plugin or parent theme file.
  2. Save an untouched backup copy of the original file somewhere separate. This readable copy stays your source of truth.
  3. Paste the JavaScript into the input box of the minifier.
  4. Press Minify JavaScript.
  5. Check the size report to see the saving. A small, lightly commented file saves little; that is expected, not a fault.
  6. Copy or download the minified code and replace the contents of the file on your site with it.
  7. Test the pages that use the script: load them, click through whatever the script drives, and check the browser console for errors. After minifying anything important, run your test suite if you have one.

Worked example: a comment removed, a string left alone

The minifier's own example shows exactly what changes and what survives. The input is:

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

The output is:

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

The real comment at the end of the first line is gone, and so is the spare whitespace around the operators. The // inside the string survives, because it is data, not a comment. The names url and x are exactly as written. On a small custom script, this is the honest scale of the win: the comments and indentation you added for yourself come off, and the logic ships unchanged.

Limitations and alternatives

The limits are plain. The tool does not integrate with WordPress, has no plugin, and does not touch PHP, so any PHP in a file you paste is outside its scope; it handles plain JavaScript only, and JSX or TypeScript syntax needs a real parser first. It is a whitespace and comment minifier, not an optimizing compiler: a tool like terser in a build pipeline goes further by renaming variables, folding constants and removing dead code, which is why its savings are larger.

For many files, that pipeline is the right route: a build tool if you already compile your theme assets, or a caching plugin's minification feature if you do not. Both repeat the job automatically on every change, which is the thing a manual paste can never do. Save the manual workflow for the one-off file that sits outside those systems.

Common mistakes

  • Minifying a plugin file. The next plugin update overwrites it, and your edit vanishes without warning.
  • Replacing the file without keeping a backup. The minified output is not meant to be edited or read; without the original, every future change starts from code nobody can follow.
  • Expecting renaming-level savings. This tool removes comments and whitespace only, so judging it against an optimizing compiler's numbers leads to a wrong conclusion about whether it worked.
  • Pasting the wrong language. PHP, JSX and TypeScript are not plain JavaScript and will not minify correctly here.
  • Skipping the test step. The tokenizer is conservative, but the only way to know a script still behaves on your pages is to load them and use what it drives.

FAQs

Does the minifier integrate with WordPress or come as a plugin?

No. It is a standalone browser tool: you paste code in and copy or download the result yourself. There is no WordPress integration and no plugin, and it does not touch PHP.

Which scripts on my site does this suit?

One small custom script that you control and can safely edit, such as a snippet in a child theme. It does not suit plugin files, which updates overwrite, or a long list of files, where a build tool or caching plugin pipeline is the better route.

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, or check the affected pages by hand on a small site.

Why is the saving smaller than a tool like terser gives?

Terser also renames variables, folds constants and removes dead code. This tool deliberately avoids rewriting your program; it just removes comments and spare whitespace.

Can I paste JSX or TypeScript?

No. Paste plain JavaScript. JSX and TypeScript syntax need a real parser first.

Conclusion

For one small custom script, minifying by hand is quick and safe: back up the original, paste, minify, check the size report, replace, and test. The moment the job grows beyond a file or two, hand it to a build tool or a caching plugin pipeline instead. For a fuller picture of what minification does and does not take out of your code, read What a JavaScript Minifier Removes: Comments, Whitespace and Names, and browse the rest of the developer tools guides for related walkthroughs.