# Minify CSS and JavaScript

- Check 06.10 · Performance and Core Web Vitals · Important
- Source: https://checklist-seo-geo.com/en/performance-core-web-vitals/minify-css-javascript
- Minify your CSS and JavaScript files at build time or from your CMS: Vite, webpack, esbuild, WordPress, Shopify, PrestaShop, Magento, Drupal.
- Updated on 2026-11-25
- Licence: CC BY 4.0. Credit “Checklist SEO & GEO” with a link to https://checklist-seo-geo.com/en/performance-core-web-vitals/minify-css-javascript.
- Plugin checklist-seo-geo: 1.3.1 · https://github.com/maximegaul/checklist-seo-geo

## In short

Minifying means removing from a CSS or JavaScript file everything that only serves humans: whitespace, line breaks, comments, long variable names. The code does exactly the same thing, in a lighter file. Once this check is done, the files served in production fit on a few very long lines and the minification warning disappears from Lighthouse reports.

## Why it matters

The browser has to download and then parse CSS before rendering the page, and download, parse and then compile JavaScript before running it. Every useless byte lengthens these steps, especially on a mid-range phone.

Minification acts at two levels:

- **transfer**: the file weighs less on the network. The gain adds to that of Brotli or Gzip compression, but it is smaller once compression is active, since compression already squeezes repeated whitespace very well;
- **parsing**: the browser has fewer characters to read after decompression. For JavaScript, the minifier also removes unreachable code and shortens names.

It is a safe optimization when the build tool does it, and today almost every tool does it by default. The work is mostly about checking that no file slips through: old scripts added by hand, theme CSS, plugin files.

## What it improves

- **Page weight**: lighter CSS and JavaScript files, even after compression.
- **Rendering**: smaller CSS blocks rendering for less time; a modest but real effect on FCP (First Contentful Paint, first render) and LCP (Largest Contentful Paint, rendering of the largest visible element).
- **Lighthouse audit**: the warnings about CSS and JavaScript resource size disappear.
- **Bandwidth**: fewer bytes served, for you as well as for crawlers.
- **Rankings**: no direct effect. The gain is small compared with removing unused code.

## How to check

Look at the shape of a file served in production:

```bash
curl -s https://example.com/css/app.css | head -c 400
curl -s https://example.com/css/app.css | wc -l
```

A minified file shows compact code, with no indentation or comments, and has very few lines. Repeat with the main JavaScript file.

Other ways:

- **PageSpeed Insights or Lighthouse**: the “Minify CSS” and “Minify JavaScript” diagnostics list the files concerned and the estimated savings. See [analyze PageSpeed Insights and Lighthouse](https://checklist-seo-geo.com/en/performance-core-web-vitals/analyze-pagespeed-insights-lighthouse).
- **DevTools**: Network tab, filter on CSS and then JS, and open the preview of each file.

Also check the third-party files you host: always prefer the `.min.js` variant provided by the vendor.

## How to implement

### Before you start

- **Minify at build time, not on every request.** The result is a static file, cached and compressed once.
- **Keep readable sources** in the repository; never edit a minified file by hand.
- **Generate source maps** to debug in production.
- **Do not minify twice.** An already minified file run through a second tool gains nothing and sometimes breaks.
- **Test after enabling it**: mobile menu, forms, cart. Aggressive JavaScript minification can break code that depends on the names of its functions.

HTML minification exists too, but its gain after compression is very small: only deal with it last.

### With a build tool

**Vite** minifies CSS and JavaScript by default in production:

```bash
npx vite build
```

**webpack** minifies JavaScript as soon as `mode` is `production`. For CSS, add `css-minimizer-webpack-plugin`:

```js
// webpack.config.js
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');

module.exports = {
  mode: 'production',
  devtool: 'source-map',
  optimization: {
    minimizer: ['...', new CssMinimizerPlugin()],
  },
};
```

The `'...'` string keeps the default JavaScript minifier.

### From the command line, without a build tool

For a site whose files are written by hand:

```bash
npx esbuild public/js/app.js --minify --sourcemap --outfile=public/js/app.min.js
npx esbuild public/css/app.css --minify --outfile=public/css/app.min.css
```

Alternatives: `terser` for JavaScript, `lightningcss` for CSS.

```bash
npx terser public/js/app.js --compress --mangle --source-map --output public/js/app.min.js
npx lightningcss-cli --minify public/css/app.css -o public/css/app.min.css
```

Then reference the `.min` files in your templates, and version their name or parameter so that [the browser cache](https://checklist-seo-geo.com/en/performance-core-web-vitals/configure-browser-server-caching) does not serve the old version.

### Apache

Versions: Apache 2.4.

Apache does not minify. The `mod_pagespeed` module, which used to do it on the fly, is no longer maintained: do not install it for this. Minify at build time or in the CMS, and leave compression and caching to Apache.

### Nginx

Versions: Nginx 1.x, all versions.

Same situation: no native minification, and `ngx_pagespeed` is no longer maintained. Serve files that are already minified.

### LiteSpeed

Versions: LiteSpeed Web Server and OpenLiteSpeed; LiteSpeed Cache 7.x plugin for WordPress.

The server does not minify on its own. On WordPress, the LiteSpeed Cache plugin handles it: `LiteSpeed Cache > Page Optimization`, CSS Settings and JS Settings tabs, minify options.

### Cloudflare

Versions: Cloudflare dashboard, all plans, November 2026.

Cloudflare retired its Auto Minify feature in August 2024: there is nothing left to enable, and older tutorials that mention it are out of date. Cloudflare compresses and caches; minification happens beforehand, at build time or in the CMS.

### AWS

Versions: CloudFront, S3 and Amplify Hosting, AWS console, November 2026.

CloudFront and S3 serve files as they are. Minify in your deployment pipeline before uploading to S3. Amplify Hosting runs your project's build command: the minification is your tool's. The same goes for Google Cloud CDN, Azure Front Door and Fastly: a CDN compresses, it does not minify.

### Plesk

Versions: Plesk Obsidian 18.0.

No minification option in the control panel. Minify locally or in the CMS, then upload the files. If Node.js is enabled on the domain, you can run your build command from the Node.js screen.

### cPanel

Versions: cPanel & WHM, versions released in 2026.

No option here either. Same approach: local build or CMS plugin.

### Shared hosting

Without access to Node.js on the server, minify on your own machine with the commands above and upload the `.min` files over SFTP, or use your CMS plugin.

### Vercel

Versions: Vercel platform, all plans, November 2026.

Vercel runs the framework's build command (Next.js, Nuxt, Astro, Vite), which minifies. Static files dropped as is into the public folder are not touched.

### Netlify

Versions: Netlify platform, all plans, November 2026.

Same principle: your build does the minifying. The old asset post-processing option (bundling and minification) reached end of life in October 2023.

### WordPress

Versions: WordPress 6.0 to 7.1; LiteSpeed Cache 7.x; WP Rocket, Autoptimize and W3 Total Cache in their November 2026 versions.

Core files are already minified as long as the `SCRIPT_DEBUG` constant is not enabled in `wp-config.php`. That leaves the theme and plugin files.

- **WP Rocket**: `File Optimization`, minify options for CSS and JavaScript files.
- **Autoptimize** (free): check the options to optimize JavaScript code and CSS code.
- **LiteSpeed Cache**, **W3 Total Cache**: equivalent options.

Enable one option at a time and test. If something breaks, exclude the offending file in the plugin settings. File combining, offered next to minification, no longer brings much with HTTP/2 and causes most incidents: leave it off.

For a custom theme, minify at build time and load the `.min` variant:

```php
add_action('wp_enqueue_scripts', function (): void {
    $suffixe = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';

    wp_enqueue_style('theme-app', get_theme_file_uri("assets/css/app{$suffixe}.css"), [], '1.4.0');
});
```

### Shopify

Versions: Online Store 2.0 themes, all plans, November 2026.

Shopify automatically minifies the CSS and JavaScript files in the theme's `assets` folder and updates the minified version with each change. Still check the files served: files containing Liquid (`.css.liquid`, `.js.liquid`) or syntax the minifier does not recognize may come out unchanged. Prefer plain `.css` and `.js` files, and pass dynamic values through CSS variables or `data-` attributes.

### PrestaShop

Versions: PrestaShop 8 and 9.

In `Advanced Parameters > Performance`, CCC section (Combine, Compress and Cache), enable the “Smart cache” options for CSS and for JavaScript, then clear the cache. Test the checkout funnel: some modules do not handle combining well.

### Magento

Versions: Adobe Commerce and Magento Open Source 2.4.x (up to 2.4.9).

In production, enable minification from the command line, then redeploy the static files:

```bash
bin/magento config:set dev/css/minify_files 1
bin/magento config:set dev/js/minify_files 1
bin/magento setup:static-content:deploy -f
bin/magento cache:flush
```

### Drupal

Versions: Drupal 10 and 11.

In `Configuration > Development > Performance`, check “Aggregate CSS files” and “Aggregate JavaScript files”, then clear all caches. Aggregation bundles the files and strips whitespace and comments from them.

### Laravel

Versions: Laravel 10 to 13, with Vite.

With Vite, the build command produces minified, versioned files in `public/build`:

```bash
npm run build
```

The `@vite(['resources/css/app.css', 'resources/js/app.js'])` directive references the right files automatically. Without a build tool, use the `esbuild` commands above and the `asset()` function.

### Next.js

Versions: Next.js 15 and 16.

`next build` minifies JavaScript and CSS with no configuration.

### Nuxt

Versions: Nuxt 3 and 4.

`nuxt build` and `nuxt generate` minify by default.

### Astro

Versions: Astro 5 to 7.

`astro build` minifies by default, including styles and scripts declared in components.

## Common mistakes

- **Loading the development build of a library in production**: `vue.js` instead of `vue.min.js`, React in development mode.
- **Minifying on the fly in the application**: CPU spent on every request for an identical result.
- **Enabling minification and combining at the same time in a plugin**, then not knowing which one broke the site.
- **Forgetting to purge**: the page cache still references the old files.
- **Forgetting inline scripts and styles**: a large `style` or `script` block in the HTML is not processed by the build tool.
- **Expecting a spectacular gain**: on a site that is already compressed, minification saves little. [Removing unused CSS and JavaScript](https://checklist-seo-geo.com/en/performance-core-web-vitals/remove-unused-css-js) pays off far more.
- **Shipping without source maps**, then debugging a production error on a single line several thousand characters long.

## Frequently asked questions

### Is minification still useful if Brotli or Gzip is active?

Yes, but the gain is smaller. Compression already squeezes repeated whitespace very well, so minification saves fewer bytes on the network once Brotli or Gzip is active. It is still worthwhile after decompression: the browser has fewer characters to parse, and the JavaScript minifier removes unreachable code and shortens names. The two optimizations add up.

### Does Cloudflare still minify CSS and JavaScript?

No. Cloudflare retired its Auto Minify feature in August 2024: there is nothing left to enable, and tutorials that mention it are out of date. Cloudflare compresses and caches; minification happens beforehand, at build time or through a CMS plugin. The same goes for other CDNs, which compress files but do not minify them.

### Can minification break a site?

It is rare when the build tool handles it, more common with CMS plugins. Aggressive JavaScript minification can break code that depends on the names of its functions, and the file combining offered alongside it causes most incidents. Enable one option at a time, test the mobile menu, forms and cart, and exclude the offending file if something breaks.

### Does minification improve SEO?

Not directly. It lightens CSS and JavaScript files, which slightly reduces render blocking, with a modest but real effect on first render and LCP, and therefore on Core Web Vitals. On a site that is already compressed, the gain stays small: removing unused CSS and JavaScript pays off far more. It also clears the corresponding Lighthouse warnings.

## Resources

- [Chrome for Developers: Minify CSS](https://developer.chrome.com/docs/lighthouse/performance/unminified-css)
- [Chrome for Developers: Minify JavaScript](https://developer.chrome.com/docs/lighthouse/performance/unminified-javascript)
- [Vite: Build options](https://vite.dev/config/build-options)
- [webpack: Optimization](https://webpack.js.org/configuration/optimization/) and [css-minimizer-webpack-plugin](https://webpack.js.org/plugins/css-minimizer-webpack-plugin/)
- [esbuild: Minify](https://esbuild.github.io/api/#minify)
- [Cloudflare: Auto Minify deprecation](https://developers.cloudflare.com/fundamentals/api/reference/deprecations/)
- [Shopify: Theme file transformation](https://shopify.dev/docs/storefronts/themes/best-practices/file-transformation)
- [Adobe Commerce: Optimizing CSS and JavaScript files](https://experienceleague.adobe.com/en/docs/commerce-operations/performance-best-practices/configuration)

Next steps: [remove unused CSS and JavaScript](https://checklist-seo-geo.com/en/performance-core-web-vitals/remove-unused-css-js) and [reduce render-blocking resources](https://checklist-seo-geo.com/en/performance-core-web-vitals/reduce-render-blocking-resources).
