JS & CSS Minifier
Remove whitespace and comments from JavaScript and CSS. See exactly how many bytes you save.
About the JS & CSS Minifier
Minification reduces JavaScript and CSS file size by removing all whitespace, comments, and unnecessary characters without changing how the code works. A well-minified JavaScript file is typically 30-60% smaller than the original source. For CSS, reductions of 20-40% are common. Smaller files load faster, consume less bandwidth, and improve Core Web Vitals scores.
What minification removes
- Whitespace — all spaces, tabs, and newlines between tokens
- Comments — both inline (//) and block (/* */) comments are stripped
- Redundant syntax — trailing semicolons, unnecessary quotes, zero-unit values (0px becomes 0)
- Variable renaming — advanced minifiers rename local variables to single letters, reducing code size further
Minification vs compression vs bundling
Minification reduces source code size on disk. Gzip/Brotli compression further reduces the transferred size over HTTP. Bundling combines multiple files into one to reduce HTTP requests. For production, apply all three: bundle files, minify the result, and serve with compression. Together they can reduce JS payload by 80-90%.
Source maps for debugging minified code
When minified code throws an error in production, source maps let you trace it back to the original source. A source map is a JSON file that maps minified variable names and line numbers back to the readable source. Browser DevTools load source maps automatically if they are available, showing the original code in the debugger and call stack.
- Generating source maps — Terser: add
--source-mapflag; webpack: setdevtool: "source-map" - Uploading to error trackers — Sentry, Bugsnag accept source maps for readable production error stack traces
- Serving source maps — source maps can be served publicly (convenient) or uploaded only to error trackers (more secure)
- X-SourceMap header — alternatively reference the source map from within the minified file via a comment at the end
Frequently Asked Questions
npx terser input.js -o output.min.js --compress --mangle. For CSS: npx cssnano input.css output.min.css. In webpack, use TerserPlugin. In Vite and Next.js, minification runs automatically when building for production.