Feedback

Minify CSS and JavaScript

Updated

Lighthouse raises Minify JavaScript and Minify CSS when a page ships files that still contain whitespace, line breaks, comments and long variable names that only matter to the developer. Minification strips all of that without changing what the code does. On its own it is a modest gain, usually smaller than compression or removing unused code, but it is cheap, it stacks with every other optimization, and an unminified file in production is a reliable sign that the build pipeline is not doing its job.

From PerfDelta's measurements: Lighthouse reports “Minify JavaScript” on 15% of 41,409 measured home pages. The median saving estimated by Lighthouse is 180 ms. More in the data section below.

What the audits check

For each JavaScript and CSS file the page loads, Lighthouse estimates how much smaller it would be after minification. JavaScript files are listed when the saving is at least ten percent and at least 2 KiB, CSS files from five percent and 2 KiB, each with the estimated byte saving (Lighthouse source code, unminified-javascript.js and unminified-css.js, version 13.6). In Lighthouse 13 both audits are unchanged and appear under Diagnostics; like all audits apart from the metrics, they carry no weight in the performance score. The audit looks at the source as transferred, so a file that is compressed but not minified still appears, because minification and compression remove different kinds of redundancy.

Minification and compression are different steps

Compression (Brotli or gzip) finds repeated byte sequences and encodes them more compactly, which already shrinks whitespace and comments a lot. Minification removes them entirely and additionally shortens identifiers, folds constants and drops dead branches, which compression cannot do. The two combine: a minified file compresses to a smaller result than the unminified original. Treat text compression as the first step and minification as the second; both belong in a production build.

How to minify JavaScript and CSS

1. Let the build tool do it

Every modern bundler minifies in production mode: Vite 8 with the Oxc minifier for JavaScript and Lightning CSS for stylesheets (older Vite versions used esbuild), webpack through Terser and the CSS minimizer plugin, Parcel by default. Plain Rollup only minifies with a plugin such as @rollup/plugin-terser. Next.js, Nuxt, Astro and SvelteKit ship minified output from their production builds without extra configuration. If the audit lists files from your own build, the usual causes are a development build deployed by mistake, a NODE_ENV that is not production, or a file copied into a static folder that bypasses the bundler.

# Vite: minified by default
vite build

# webpack: production mode enables Terser
webpack --mode production

2. Minify at the CDN or server

Some CDNs, hosting platforms and server modules can minify JavaScript and CSS on the fly. Cloudflare is no longer one of them: it retired Auto Minify on 5 August 2024 (Cloudflare API deprecations). Where such a feature exists, it is a reasonable fallback for files you do not control, but it is riskier than build-time minification: an on-the-fly minifier cannot run tests, and a rare syntax edge case breaks the live site instead of the build. Prefer the build step for your own code and use CDN minification for the rest.

3. WordPress, Shopify and other platforms

4. Minify inline code too

Lighthouse also checks inline <script> and <style> blocks and lists them as “inline: …” when they are large and unminified. Inline code also adds to the document size and cannot be cached separately, so keep it short, move anything over a few kilobytes into a cacheable external file, and let the template engine strip HTML whitespace in production.

5. Keep source maps out of the production bundle

Source maps are useful for debugging but must not be inlined into production files, where they can multiply the file size. Emit them as separate .map files that only developer tools request, or upload them to your error tracker instead of the public server.

What minification is worth

How much minification removes depends on how verbose the source is: hand-written code with comments and long names shrinks more than code a bundler has already processed. After Brotli or gzip compression the remaining difference is usually much smaller than before, because compression already removes most repetition. It is rarely the fix that turns a failing LCP into a passing one. The findings that move Core Web Vitals are unused JavaScript, render-blocking resources and JavaScript execution time. Minification is the hygiene step that makes those gains a little larger and signals that the pipeline is sound.

Frequently asked questions

Can minification break my site?

Build-time minification with a current minifier is safe for standard JavaScript and CSS. Problems come from code that relies on function names at runtime, from very old syntax, or from on-the-fly minifiers that combine files in a different order. Test after enabling, especially on WordPress, where plugin options combine files as well.

Why does Lighthouse flag a file that is already minified?

Some minified files still contain license comments, inline source maps or large embedded data. Check the file in the browser: if it is one long line but very large, the content rather than the formatting is the issue, and the right audit is unused JavaScript.

Should I combine files as well as minify them?

With HTTP/2 and HTTP/3, combining many files into one no longer helps as it did with HTTP/1.1 and can hurt caching. Minify every file, but combine only where a build tool does it with proper dependency handling.

Does minifying HTML count?

Lighthouse does not audit HTML minification separately, but a smaller document arrives sooner and helps First Contentful Paint. Most template engines and static site generators can strip whitespace in production.

What PerfDelta's measurements show

Lighthouse reports “Minify JavaScript” on 15% of 41,409 measured home pages. The median saving estimated by Lighthouse is 180 ms.

Lighthouse reports “Minify CSS” on 11% of 41,409 measured home pages. The median saving estimated by Lighthouse is 150 ms.

Data as of November 30, 2026, recalculated daily. Source: PerfDelta's own measurements (Chrome UX Report and Lighthouse); details in the website speed statistics and the methodology.

Thresholds and sources

Sources:

All sources retrieved on October 9, 2026. Thresholds and documentation change; the linked page is authoritative.

Test your site

Run a free scan to see whether this applies to your pages, on mobile and desktop, with lab and field data side by side.

Run a free test

A free account saves your tests and shows how your values change from one test to the next. Website performance monitoring with field data and alerts starts with the Solo plan.

Related audits