Minification removes spaces and comments from JavaScript and CSS files, so browsers download less before a page becomes usable. On mobile, unminified files show up as pages that appear but don’t respond to taps for a moment, and they lower your Core Web Vitals scores.

Check the mode first

bin/magento deploy:mode:show

In developer mode, minification settings are ignored. If the store is in developer mode, switching to production fixes this and much more (see switching from developer mode).

Enable minification in production

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

Test before and after

Minification occasionally breaks a third-party script that wasn’t written with it in mind. After enabling it:

  • Click through the storefront, cart and checkout with the browser console open, and look for errors.
  • Check the admin too. If one area breaks, you can enable minification for CSS and HTML and leave JavaScript off until the faulty module is fixed.

What about bundling?

Magento’s built-in JavaScript bundling (dev/js/enable_js_bundling) often creates very large files and can make things slower. Test carefully, or use HTTP/2 without bundling, which works well for most stores.

Catch it automatically

MageMonitor checks for this every few minutes as part of its performance checks, and alerts you by email, Slack or webhook the moment it appears, with the exact commands to fix it. See MageMonitor for Magento 2.

Related fixes