How to Minify JavaScript to Improve Page Speed

How to Enable Both

Minify your CSS with an online minifier or a build tool like cssnano. Then enable Gzip or Brotli in your server or CDN configuration, or through a caching plugin if you use WordPress. Most modern hosts support Brotli, which compresses slightly better than Gzip.

What Is JavaScript Minification?

JavaScript minification removes characters the browser does not need to run your code, such as whitespace, comments and line breaks, and shortens local variable names. The output runs exactly like the original script but is significantly smaller and faster to download and parse.

How to Minify JavaScript Online

Using an online JavaScript minifier is the fastest route. Paste your code or upload a .js file, click Minify or Compress, then copy the result or download a .min.js file. It requires no setup and works well for single files or when you do not want to change your build configuration.

How to Minify JavaScript With Build Tools

For active projects, minify automatically with build tools. Terser, esbuild and UglifyJS integrate with Webpack, Vite, Rollup and Gulp to minify every build. These tools also rename variables and remove dead code for even smaller output, while your source stays readable.

Minification vs Compression vs Bundling

These three techniques work together. Minification rewrites the code more compactly. Bundling combines many files into fewer requests. Compression such as Gzip or Brotli shrinks the bytes sent over the network. Using all three produces the smallest, fastest JavaScript payload.

How Minifying JavaScript Improves Page Speed

Large scripts delay Largest Contentful Paint, block the main thread and hurt Interaction to Next Paint. Minified JavaScript sends fewer bytes and gives the browser less code to parse and execute, which directly improves these Core Web Vitals and the page experience signals Google uses for ranking.

Best Practices for Minifying JavaScript

Keep an unminified source version and deploy only the minified build. Never hand-edit a minified file. Load non-critical scripts with defer or async, and re-minify on every release so users always receive the smallest, fastest version of your code.

Frequently Asked Questions

Is it safe to minify JavaScript?

Yes. Minification is lossless when done by a reliable tool, so your compressed code behaves exactly like the original.

Can I minify jQuery too?

Yes. jQuery is JavaScript, so any good JavaScript minifier will compress it while keeping it compatible with plugins and browsers.

What is the best JavaScript minifier?

Terser is the most popular build-time minifier, while a free online JavaScript minifier is ideal for quick, one-off compression.