DeveloperMar 31, 2026 ยท Updated Oct 13, 2026 ยท 3 min read

How to Minify CSS and JavaScript for Production

How much minification actually saves, measured on lodash, jQuery, Bootstrap and normalize.css: compression does most of the work for CSS, while JavaScript needs a real minifier (terser halved what whitespace-stripping left of lodash).

๐Ÿ“ฆ
Try the Code Minifier
Free, no signup
โ†’
DG
Derek Giordano
Designer & Developer
In this guide
01What Minification Does02Measured on Four Real Files03In Practice

What Minification Does

A minifier rewrites code to be smaller without changing what it does. The safe part is removing whitespace and comments and shortening values (0px to 0, #ffffff to #fff). JavaScript minifiers such as terser go further: they rename local variables, drop unreachable code and fold constants, which needs a full parser of the language.

Measured on Four Real Files

We minified four widely used files from npm with our Code Minifier (whitespace and comments only, token-aware so strings and regular expressions are left alone) and with the standard tools, then compressed each result as a server would (October 14, 2026; script in our test folder):

FileRawOur minifierterser / clean-cssRaw + BrotliMinified + Brotli (best)
lodash 4.17.21 (JS)544 KB149 KB71 KB (terser)74 KB22 KB
jQuery 3.7.1 (JS)285 KB141 KB87 KB (terser)70 KB28 KB
Bootstrap 5.3.3 (CSS)281 KB232 KB233 KB (clean-css)25 KB23 KB
normalize.css 8.0.16.1 KB1.8 KB1.8 KB (clean-css)1.4 KB0.6 KB

Three lessons. First, compression does most of the work for CSS: Bootstrap shrank 17% by minifying but 91% by Brotli alone, and minifying on top of Brotli saved another 8%. Second, JavaScript gains far more from a real minifier: terser's renaming and compression cut lodash to half the size our whitespace-only pass reached, and after Brotli the difference was 22 KB against 31 KB. Third, comments matter: lodash is mostly documentation comments, which is why simply stripping them removed 73% of it.

Correctness check: the lodash our tool produced still ran in Node (_.chunk and _.template gave the right results) and the minified jQuery still parsed.

In Practice

Frequently Asked Questions

What is code minification?+
Minification removes whitespace, comments, and unnecessary characters from CSS and JavaScript without changing the code's behavior. It reduces file size, which improves download speed and page load time.
Does minification affect performance?+
Yes, mostly through download size, and less than compression does. In our test Brotli alone cut Bootstrap's CSS by 91% and minifying first saved another 8%; for JavaScript a full minifier (terser) cut lodash after Brotli from 74 KB to 22 KB. Savings vary a lot by file: comment-heavy sources shrink most.
Should I minify in development?+
No. Minified code is unreadable and hard to debug. Minify only for production builds. Use source maps to enable debugging of minified code when needed.
Try it yourself

Use the Code Minifier โ€” free, no signup required.

โšก Open Code Minifier
DG
Derek Giordano
Written by the creator of Ultimate Design Tools. BA in Business Marketing.