Check 06.10 · Performance and Core Web Vitals

Minify CSS and JavaScript

Minify your CSS and JavaScript files at build time or from your CMS: Vite, webpack, esbuild, WordPress, Shopify, PrestaShop, Magento, Drupal.

Priority
Important
Difficulty
Easy
Estimated time
30 min to 2 h
Free, no account: your progress is saved in this browser.

Ask an AI to check this point on your site

Opens the assistant with a ready-made question: this check, its goal and your site URL.

For Gemini, Copilot or another assistant, copy the question. The link opens the chosen service directly: nothing goes through this site.

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:

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:

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:

npx vite build

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

// 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:

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.

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 (opens in a new tab) 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:

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:

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:

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 (opens in a new tab) 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.

Updated on

Topic checklist (PDF)

And now?

In the “Performance and Core Web Vitals” topic

  1. Analyze PageSpeed Insights and Lighthouse
  2. Analyze real-user CrUX data
  3. Target LCP ≤ 2.5 s at the 75th percentile
  4. Target INP ≤ 200 ms at the 75th percentile
  5. Target CLS ≤ 0.1 at the 75th percentile
  6. Target TTFB ≤ 800 ms as a benchmark
  7. Optimize hosting and CDN
  8. Enable Brotli/Gzip
  9. Configure browser and server caching
  10. Minify CSS and JavaScript
  11. Remove unused CSS/JS
  12. Reduce render-blocking resources
  13. Defer non-essential scripts
  14. Limit third-party scripts
  15. Optimize database queries
  16. Optimize fonts (WOFF2, font-display)
  17. Preload only critical resources
  18. Optimize the LCP image without lazy loading
  19. Lazy-load offscreen content
  20. Reserve space for media and ads
  21. Reduce DOM complexity
  22. Test before and after cookie consent
  23. Test on a slow mobile connection
  24. Set a performance budget
  25. Preload likely navigations with Speculation Rules
  26. Make pages eligible for the back/forward cache (bfcache)
  27. Diagnose INP with Long Animation Frames (LoAF)