JS / CSS minification

Last updated 17 June 2026 3 min

Minification is the process of reducing the size of JavaScript and CSS files by removing characters that aren't needed for the code to run. The output is functionally identical to the input but smaller — typically 20–50% smaller for JavaScript and 30–70% smaller for CSS.

What gets removed

  • Whitespace — spaces, tabs, line breaks.
  • Comments — both inline (//) and block (/* */).
  • Unnecessary semicolons (in some cases).

JavaScript minifiers also typically:

  • Inline simple expressions.
  • Combine consecutive statements.

CSS minifiers also:

  • Merge duplicate rules.
  • Shorten colour values (#ffffff#fff).

A 100 KB readable JavaScript file might become a 40 KB minified file, and roughly 8 KB after Brotli compression on top.

Minification vs. compression

These are different and complementary:

  • Minification — done at build time. Permanent change to the file content.
  • Compression (gzip, Brotli) — done at the server level when the file is served. The original file is unchanged.

A minified file compresses to be smaller than a non-minified file, so both should be used together.

What minification looks like

Before

/* Primary navigation */
.nav-primary {
  display: flex;
  align-items: center;
  background-color: #ffffff;
  padding: 16px 24px;
}

After

.nav-primary{display:flex;align-items:center;background:#ffffff;padding:16px 24px}

Why it matters for SEO

Smaller JavaScript and CSS files mean:

  • Faster downloads — particularly impactful on mobile networks.
  • Faster parsing — less text for the browser to read through.
  • Faster Largest Contentful Paint (a Core Web Vital) and First Contentful Paint.
  • Better PageSpeed Insights scores — minification is a standard audit check.

Since Core Web Vitals are a confirmed ranking signal, minification contributes indirectly but reliably to SEO performance.

How it's done

Build-step minification

Many modern frontend stacks minify automatically in production builds:

  • Webpack — Terser plugin (JS), CssMinimizerPlugin (CSS).
  • Vite — esbuild (default) or Terser for JS, esbuild for CSS.
  • Rollup — Terser plugin.
  • Parcel — built in.
  • Next.js, Nuxt, SvelteKit — minify by default in production.

CMS plugins

  • WordPress — Autoptimize, WP Rocket, LiteSpeed Cache, FlyingPress all handle minification.
  • Shopify — minification is partially automatic; theme-level optimisation often needs developer work.
  • Magento — built-in minification flags in admin (Stores → Configuration → Advanced → Developer).

Manual / on-demand

  • Online tools like minifier.org, csscompressor.com (fine for one-off use, not for production).

Common pitfalls

  • Minifying already-minified files — double minification rarely fails outright but adds nothing.
  • Minifying source files in version control — minify only the build output, never the source.
  • Aggressive minification breaking code — particularly older JavaScript using string-based property access or relying on function names. Modern minifiers handle most cases, but legacy code can break.
  • Forgetting to invalidate cache — after a deploy, old minified files can persist in browser or CDN caches. Use cache-busting filenames (app.min.a3f9b2.js) so each new version has a unique URL.
  • Inline scripts and styles not minified — build pipelines typically only handle external files. Inline <style> and <script> blocks need to be minified separately or moved to external files.

Verifying it's working

  • View source on a production page. Minified files are dense, single-line or near single-line.
  • Open DevTools → Network → look at file sizes. Minified JavaScript should be a fraction of the readable source size.
  • Run PageSpeed Insights. Unused or unminified JS/CSS appears in the opportunities list.

Disclaimer: All information contained herein is for informational purposes only. It is not advice or instructional.