JavaScript Minification
What JavaScript minification is, how our report decides a script is minified, and the fastest ways to fix unminified files.
Free to use 9 min read Updated Oct 2026
What Is JavaScript Minification? The Quick Answer
Quick answer: JavaScript minification strips whitespace, comments and long names from a script so the file is smaller and quicker to download and parse, while the code behaves the same. Our report downloads your external script files and checks whether each script file looks minified.
- Pass: every external script file the report checked looks minified.
- Warning: a mix of minified and unminified JavaScript files.
- Fail: none look minified, none could be fetched, or the page has no external script.
- Fix: build with a minifier such as Terser, or switch your bundler to production mode, then serve the .min.js or hashed file it produces.
What JavaScript Minification Does to Your Code
To minify JS is to minimize JavaScript without changing what it does. A minifier strips whitespace and comments, then mangles variable names down to a letter or two. Better ones such as Terser add dead code elimination and fold constant expressions, the compress step in the command later. Source maps show your original lines in DevTools. The MDN minification glossary entry defines it neutrally.
Before and after on a small function
A readable function comes first, then what a minifier typically writes.
// source
// add sales tax to a price
function addTax(price, rate) {
var total = price * (1 + rate);
return total;
}
// minified
function addTax(n,t){return n*(1+t)}The comment, indentation, temporary variable and long parameter names are gone, yet addTax(100, 0.2) still returns 120.
Minification vs compression vs obfuscation
Minification changes the file itself during your build. Gzip and Brotli compression packs the bytes in transit, and the two stack (our gzip compression guide covers that side). Obfuscation vs minification comes down to intent: obfuscation tries to hide logic and often makes the file bigger, while a minified file is only harder to read, not protected.
Why Minifying JavaScript Matters for Speed and SEO
We compressed jQuery 3.7.1 in both forms; gzip figures vary by a few hundred bytes between implementations.
| Version | Raw bytes | gzip level 6 | Brotli quality 5 |
|---|---|---|---|
| Source as published | 285,314 | about 84,000 | 79,680 |
| Minified (jquery.min.js) | 87,533 | about 30,400 | 29,763 |
| Saving from minifying | about 69 percent | about 64 percent | about 63 percent |
The last row matters most. Even when the server already compresses text (the audit Lighthouse calls Enable text compression), minifying first still cuts roughly two thirds of the bytes sent. That is a big cut in JavaScript file size for what is usually one build setting.
Smaller scripts download sooner on slow connections and give the browser less to parse, which contributes to Largest Contentful Paint, one of the Core Web Vitals. That is a contribution, not a ranking switch. When parsing blocks the main thread it also touches Interaction to Next Paint, and heavy third party code still causes long tasks, and our JavaScript execution time guide covers that.
How SEO Site Checker Tests JavaScript Minification
The test is a line length heuristic you can reproduce by hand.
The rule: for each external script file, divide the total characters by the number of lines. An average line length above 200 characters counts as minified. 200 or below counts as unminified.
What the check reads
We render your page in headless Chromium and parse the final HTML, so scripts added by JavaScript are seen too. We collect the first 8 external script tags in page order and skip inline code, because there is no file to download for it. Each file is fetched on its own with a 3 second timeout, and the whole batch gets about 10 seconds.
How one file is judged
In our tests jQuery 3.7.1 source averaged 25.6 characters per line and was flagged, while jquery.min.js averaged 43,765. The lodash 4.17.21 build averaged 520 and the React 18.3.1 production build averaged 346, so both passed. A file we cannot fetch is counted as unminified.
Pass, warning and fail
| Status | Condition | What to do |
|---|---|---|
| Passed | At least one file fetched and none of the checked files is unminified | Nothing to change |
| Warning | At least one file is minified and at least one is not | Minify the files that missed |
| Failed | No file looked minified, every fetch failed, or the page has no external script file | Minify, confirm the files load, or ignore it if the page really has no external scripts |
The report also shows how many files it checked (8 at most) and, once you sign in, the minified and unminified URLs.
Known blind spots
Line length is only a proxy, so it can be wrong.
- Banner comments. A small file with a long license banner can fall under the limit: our 1,152 byte test file minified with Terser averaged 128 and was flagged.
- Wrapped output. Output wrapped near 120 characters is flagged too: jQuery wrapped that way averaged 99.5.
- Scheme relative URLs and timeouts. A scheme relative URL starting with // counts as unminified. So does a file that fails to download, and the 10 second batch limit can leave slow files out of the count.
- Path joining. Relative paths such as js/app.js are joined to your site root, not the page, so on a nested page we may fetch a different file from the one the browser loads.
This scan also feeds caching, covered in our JavaScript caching guide. To see your own numbers, run the free SEO report on your URL.
How to Check if JavaScript Is Minified
- Open the file. Minified JavaScript is a few dense lines of short names.
- Compare in DevTools. In the Chrome DevTools Network panel, filter by JS, reload and compare size with transfer size.
- Measure the line length. Swap /js/app.js below for your own script path and run it in the console on the same site, since other origins may block the fetch. Above 200 matches our rule closely.
fetch('/js/app.js')
.then(r => r.text())
.then(t => console.log(t.length / t.split('\n').length));If your Lighthouse or PageSpeed Insights version includes it, the Lighthouse Minify JavaScript audit lists estimated savings in KiB. It documents no pass threshold, so it and our rule can disagree on edge cases.
How to Minify JavaScript Files Step by Step
Use a one-off command or a build setting that minifies on every deploy.
- Keep readable source. Generate minified copies during the build, never by hand.
- Quick route with Terser. Install it with npm and run the command below. The -c flag compresses and -m mangles names, and the source map it writes lets DevTools map errors back to src/app.js (drop the source map option if you do not want a map file).
- Bundler route. Code splitting and bundling reduce how many scripts a page loads, and minification shrinks what remains. Webpack production mode minimizes output through TerserPlugin, so set mode to production. Vite minifies during vite build by default, though the minifier depends on the version (current docs name Oxc, older releases used esbuild).
- Update the script tag. Point it at the new .min.js file or hashed bundle and remove the old reference.
- Test and re-scan. Click through forms and payments, then run the report again.
npm install terser --save-dev
npx terser src/app.js -c -m --source-map "url=app.min.js.map" -o dist/app.min.jsUglifyJS, SWC, esbuild, Rollup plugins and Google Closure Compiler do similar work, and tree shaking trims what ships. The webpack optimization settings explain the minimize option. For a quick one-off job, our free JavaScript Minifier will shrink a pasted script without any setup, though for the report a build tool gives a safer result.
Tool limit: our minifier does not shorten names and keeps some line breaks, so a small file can still average under 200 characters per line.
A longer walkthrough is in our post on how to minify HTML, CSS and JavaScript.
How to Minify JavaScript in WordPress, Shopify and Cloudflare
Where the fix lives depends on who builds your scripts. Platforms handle some files for you and leave the rest to you.
| Platform | Where to start | Watch out for |
|---|---|---|
| WordPress | Core serves minified scripts unless SCRIPT_DEBUG is true in wp-config.php | That covers core only, so theme and plugin files need a plugin |
| Shopify | Shopify minifies theme CSS and ES5 JavaScript for you | Newer syntax, apps and inline code are not covered, so minify those yourself and upload them as .min.js |
| Cloudflare | Minify during your build or at the origin | Cloudflare Auto Minify has been retired |
| React and bundled apps | Deploy the production build | A development build ships readable code |
| Third party scripts | Ask the vendor for a .min.js build or a hosted copy that is already minified | Remove the tag only if you no longer need the feature |
To minify JavaScript in WordPress, use a plugin. In Autoptimize, tick Optimize JavaScript Code on the JS, CSS and HTML tab. In LiteSpeed Cache, turn on JS Minify under Page Optimization, JS Settings.
Common JavaScript Minification Mistakes
- Skipping the test. Code that reads function.name, builds names as strings, or is joined with other files without semicolons can break after minifying.
- Losing the source. Deleting the original files or source map makes errors hard to debug.
- Pointing at the old file. If the script tag still references the unminified URL, the report never changes.
- Forgetting third party files. They are judged like yours, and one unminified file is enough for a warning.
- Stopping at minification. Scripts that block rendering still need defer, which our render blocking resources guide covers.
How to Fix
The short version, the same steps you see when you click How to Fix in your report.
Why this fails: at least one script file on your page still has readable, indented lines and comments, or none of the files could be fetched. It can also trigger when your files are minified but small, wrapped near 120 characters or topped by a long license banner, or when the page loads no external scripts at all. Our check downloads up to 8 external scripts and treats an average above 200 characters per line as minified.
How to fix it:
- Open the unminified list in the report (sign in to see the URLs) or view the page source, and note which script files you own.
- Run Terser on each file you own, or switch your bundler to production mode so it minifies for you.
- Update each script tag to point at the new .min.js or hashed file, and remove the old reference.
- Ask the vendor of any third party file for a minified build, or remove the tag.
Terser command, with a source map:
npx terser src/app.js -c -m --source-map "url=app.min.js.map" -o dist/app.min.jswebpack.config.js:
module.exports = { mode: 'production' };Updated script tag:
<script src="/js/app.min.js" defer></script>- WordPress: switch SCRIPT_DEBUG off (it only affects core scripts), then enable JS minify in Autoptimize or LiteSpeed Cache for theme and plugin files.
- Shopify: Shopify only minifies ES5 JavaScript and skips files already named .min.js, so minify newer syntax files yourself and check apps and inline code.
- Cloudflare: it no longer minifies for you, so minify in your build or at the origin.
Average line length check (add -L to curl if the URL redirects):
curl -s https://example.com/js/app.min.js | awk '{c+=length($0); n++} END {print c/n}'Re-test: open the script URL and confirm a few dense lines, or print its average line length with the command above, where a result comfortably above 200 should pass. Then run our free SEO report again and look for Passed on JavaScript Minification.
Frequently Asked Questions
Does minifying JavaScript improve performance?
Is JavaScript minification the same as compression?
Will minifying JavaScript hurt my SEO?
How do I know if my JavaScript is already minified?
How does this check decide a script is minified?
How do I minify JavaScript in WordPress?
Do I still need to minify JavaScript if I use webpack or Vite?
Is minifying JavaScript the same as obfuscating it?
See how your site scores right now
Paste your address into the free report, then use the How to Fix button on anything that needs work.
Free to use. Results in under a minute for most sites.