Last updated
Multi-Language Code Minification
Code minification reduces file size by removing whitespace, comments, and shortening identifiers. Different languages require different minification tools because each has its own syntax and semantics. The goal is always the same: produce functionally identical code in fewer bytes.
Minification Tools by Language
| Language | Tool | Typical Reduction |
|---|---|---|
| JavaScript | Terser, esbuild, SWC | 40–70% |
| TypeScript | esbuild, tsc + Terser | 40–70% |
| CSS | cssnano, Lightning CSS | 20–40% |
| HTML | html-minifier-terser | 10–30% |
| JSON | JSON.stringify(data) | 10–20% |
| Python | pyminifier, python-minifier | 30–50% |
| SQL | Remove comments/whitespace | 10–30% |
esbuild — Fastest Multi-Language Minifier
JavaScript
import * as esbuild from 'esbuild';
// Minify JavaScript
const jsResult = await esbuild.transform(jsCode, {
minify: true,
target: 'es2020'
});
// Minify CSS
const cssResult = await esbuild.transform(cssCode, {
loader: 'css',
minify: true
});
// Bundle + minify a file
await esbuild.build({
entryPoints: ['src/app.ts'],
bundle: true,
minify: true,
outfile: 'dist/app.min.js',
target: ['chrome90', 'firefox88', 'safari14']
});