JS minifier

5 of 2 ratings
JS minifier

JS minifier is a free tool that removes unnecessary characters from JavaScript and reports the character count before and after minification.

What problem does JavaScript minification solve?

JavaScript minification reduces the amount of source text that a browser must download. It commonly removes formatting such as indentation, line breaks and spacing where those characters are not required by JavaScript syntax.

A smaller script can reduce transfer size and parsing work, particularly when a site ships several large bundles. HTTP compression such as Brotli or gzip still matters because minification and transfer compression solve different parts of the problem. Minification removes source characters, while compression encodes repeated data more compactly during transfer.

The operation is usually performed during a pre-deployment build. It is also useful when checking an unminified third-party script, comparing bundle sizes or preparing a standalone file for a site that has no build pipeline.

Minification does not prove that the JavaScript behaves correctly. A script may minify successfully while still containing incorrect API calls, inaccessible variables or code that fails only at runtime.

How do I use the JS minifier?

Paste the JavaScript into the JS field and run the tool, then copy the value returned in Minified JS. Keep the original source file in version control and deploy the compact copy rather than replacing the readable source.

  1. Run a syntax check, linter and automated tests against the source code first.
  2. Paste the complete script into JS, including any module imports or wrapper functions that belong to the file.
  3. Review JS characters and Minified JS characters to see the change in character count.
  4. Test that the minified JavaScript executes correctly in the same browser and deployment context as the production file.
  5. Use a recognisable filename such as app.min.js if the minified and readable versions will be stored together.
The JS minifier tool on digily.link, showing its input form

The work is done on the server. Your input travels to the server over HTTPS and is not stored. The server must still receive the JavaScript to process it, so do not submit source that your organisation prohibits sending to an external service.

What does the minified result contain?

The result contains the compact JavaScript and two character counts. JS characters is the input length, while Minified JS characters is the length of the returned Minified JS.

The counts are produced using PHP's mb_strlen function, which measures multibyte string length rather than simply reporting the number of bytes. Character count is therefore not the same as the final network transfer size. UTF-8 characters may occupy more than one byte, and gzip or Brotli can reduce the transmitted file further.

This tool does not return a separate validation or diagnostic field. Do not expect it to identify every missing bracket, malformed regular expression or unsupported language feature. In particular, errors associated with JSON, such as unquoted property names or trailing commas, are not reliable JavaScript checks because JavaScript object literal syntax and JSON syntax differ. Use JSON validator & beautifier for JSON data.

Example result produced by the JS minifier tool

Small examples and awkward input

A simple spacing change can be represented as follows.

Input

function add(a, b) { return a + b; }

Compact form

function add(a,b){return a+b;}

Formatting around an object can also be removed without changing its property values.

Input

const settings = { theme: "dark", retries: 2 };

Compact form

const settings={theme:"dark",retries:2};

Exact formatting can vary between minifiers, especially around optional semicolons. JavaScript cannot be compacted safely by deleting every space or line break. Safe minification must account for lexical and syntactic context to distinguish formatting from characters that affect the program.

  • Spaces in strings are data. The space in "Newcastle upon Tyne" must remain.
  • Punctuation can be syntactic. Removing the space from a + +b may produce a different token sequence.
  • Line breaks sometimes affect automatic semicolon insertion, including code following return, break or continue. A line break immediately after throw is not permitted because its expression must begin on the same line.
  • Accented and non-Latin characters may appear in strings and, where JavaScript identifier rules permit, in identifiers. Their byte size can differ from their character count.
  • Numbers are source tokens, not character-count instructions. A minifier must preserve their numeric meaning even if it chooses a shorter equivalent notation.

When is minifying JavaScript not worth doing?

Minification is usually not worth repeating when a file is already minified. A second pass may save little or nothing, while making build output harder to trace and potentially interfering with existing source maps.

There is also little reason to prettify and then minify JavaScript that only a machine will read. Keep human-readable source for maintenance and generate deployment artefacts from it. For an established application, a build tool such as esbuild, Rollup or webpack is generally more suitable because it can automate module bundling and source-map generation. Minification may be built in or added through configuration or a plugin, while Terser is a dedicated minifier.

Do not treat minification as obfuscation or access control. Function and variable names may remain visible, string literals can still be read, and browser developer tools can reformat compact code. Secrets, private keys and privileged credentials must never be embedded in client-side JavaScript.

If you are preparing all of a page's static assets, CSS minifier and HTML minifier can apply the corresponding operation to those formats. Keep each format in its own tool because their parsing and whitespace rules are different.

Frequently asked questions

Does the tool generate a source map?

No source-map field is returned. If you need production stack traces to map back to original files, generate the minified script and its matching .map file in the same build process. Deploying a source map from a different build can produce misleading line and column references.

Can minification stop people copying my JavaScript?

No. Browsers must receive executable client-side code, so a visitor can download and inspect it. Minification makes the source less readable but does not provide confidentiality, licensing enforcement or meaningful protection for embedded secrets.

Can I paste code containing API keys?

You should not paste secret API keys, tokens or private credentials. The input is sent over HTTPS and is not stored, but processing occurs on the server. Public browser keys that are deliberately distributed to every visitor still need domain, origin, quota or permission restrictions where the relevant service supports them.

Will a smaller character count always make the page load faster?

No. The effect depends on the original file size, caching, connection conditions, server compression and how much JavaScript the browser must parse and execute. Check the compressed transfer size and runtime behaviour as well as the character totals.

Should I keep the .js extension after minifying?

Yes. Minified JavaScript normally retains the .js extension, with .min.js used as a naming convention when both versions are present. Before deployment, confirm that the server sends an appropriate JavaScript content type and that the HTML or module import points to the intended file.

Similar Tools

HTML minifier

Minify your HTML files by removing unnecessary characters with our HTML minifier tool for optimised web performance.

5,248
58
CSS minifier

Optimize your CSS files by removing unnecessary characters using our CSS minifier tool for faster website loading.

4,754
40

Popular Tools