Home / Fix guides / Speed and Core Web Vitals

How to Minify CSS and JavaScript

Minifying removes spaces, line breaks and comments from your CSS and JavaScript files so they download faster, without changing how your site works. Most sites can do it with one plugin, one setting or one build step.

Minifying means stripping the extra characters out of your CSS and JavaScript files: spaces, line breaks, comments and long names. The code does exactly the same job, it just takes up less room. If a speed test says your files are "unminified", your site is sending more data than it needs to.

What the problem looks like

Visitors never see it directly. The page simply loads a little slower than it could, especially on phones and slower connections. In a speed test you may see a warning such as "Minify CSS" or "Minify JavaScript". The exact wording depends on the tool and its version.

If you open one of your files in a browser, an unminified file looks like neatly indented, readable code with comments. A minified file is a few very long, dense lines. Here is the same CSS before and after:

/* Main button */
.button {
  color: #ffffff;
  padding: 12px 24px;
}
.button{color:#fff;padding:12px 24px}

Minified files often have .min in the name, such as style.min.css or app.min.js, but the name alone proves nothing. Look at the content.

Why it matters

Smaller files download sooner. CSS is render blocking, which means the browser waits for it before showing the page, so heavy CSS delays what visitors first see. JavaScript has to be downloaded and processed before it can run, which affects how quickly the page responds to taps and clicks. Both feed into Core Web Vitals, which Google includes among its page experience signals.

For a business, the practical result is a page that feels slower, and slow pages tend to lose visitors before they read, call or buy.

Be realistic about the size of the win. Minifying usually gives a modest improvement on its own. Large images, missing compression and too many scripts normally cost more. It is still one of the easier fixes because it carries little risk when done properly.

How to check if your site has it

All of these are free.

  1. Go to PageSpeed Insights (pagespeed.web.dev), enter your page address and run the test. Open the diagnostics or opportunities list and look for minify items. Test your home page and one or two key pages, such as a product or contact page.
  2. In Chrome, press F12, open the Network tab, reload the page and filter by CSS or JS. Click a file and read the Response. Readable code with indentation means it is not minified.
  3. Right-click your page, choose View Page Source, and click the links to your .css and .js files. They open as plain text you can inspect.

Some flagged files will belong to other companies, such as chat widgets, analytics or ad tools. You cannot edit those. Your options are to leave them, replace them or remove the ones you no longer need.

SiteMonday checks this as part of its week 4 speed and Core Web Vitals service, and lists it in a ranked fix list so you can see where it sits compared with other speed problems.

How to fix it in general

There are three usual routes, from easiest to most technical.

  • Use a setting or plugin. Most content management systems and speed plugins have a minify option. This is the best route for most small business sites.
  • Use a build tool. If a developer maintains your code, minification is normally a build step. Well-known tools include Terser and esbuild for JavaScript, and cssnano and clean-css for CSS.
  • Minify by hand. For one or two small files you can paste the code into an online minifier and upload the result. Always keep the original readable file, because you will need it for future edits.

Whichever route you choose, only minify files you own. Libraries you downloaded usually ship with a .min version already, so use that one.

Common platforms

Menu names change between versions and themes, so treat these as pointers on where to look.

  • WordPress: Many caching and optimisation plugins include "minify CSS" and "minify JavaScript" options, usually under a section called Optimization, Speed or File Optimization. WP Rocket, Autoptimize and LiteSpeed Cache are well-known examples. Turn on one option at a time. See the WordPress guide.
  • Shopify: There is no single minify switch. Themes from the Theme Store are usually already minified, so the common culprits are older custom themes and files added by apps. Check which apps load scripts and remove ones you do not use. See the Shopify guide.
  • Cloudflare: Cloudflare retired its Auto Minify feature in 2024, so if you are looking for it in the dashboard, it will not be there. Minify at the source (your site, plugin or build) instead.
  • cPanel hosting: cPanel has no built-in minifier. Minify the files on your computer or through your site's plugin or build, then upload them.
  • Magento, Joomla, Drupal: All three have built-in or add-on options to combine and minify CSS and JavaScript. Look in the performance or development settings, and check whether it depends on your version.

When you turn on options that combine files as well as minify them, test carefully. Combining can break scripts that depend on loading in a certain order.

How to confirm the fix worked

  1. Clear your site cache and any plugin or CDN cache, so the old files are not still being served.
  2. Run PageSpeed Insights again on the same pages and check that the minify warnings are gone or smaller.
  3. Open the Network tab and compare file sizes with before.
  4. Use the site like a customer: open the menu, submit a form, search, add something to the basket and go through checkout. Do this on a real phone as well as a computer.

If something breaks, switch off the last setting you changed and test again. Broken layouts or dead buttons usually come from one file, and many plugins let you exclude a single file from minification.

Speed scores move around a little between runs, so test two or three times rather than judging on one result.

How to stop it coming back

  • Keep the original readable source files, and never edit minified files directly.
  • Let a plugin or build process do the minifying automatically, so new changes are covered without anyone remembering.
  • Retest after installing a new plugin, app or theme update, because these often add new files.
  • Remove scripts and plugins you no longer use.
  • Make sure your server also compresses text files. Minifying and compression work together, and the no text compression guide explains the second half.

A quick speed test every few months is enough to catch most regressions before visitors notice them.

Step by step for your platform

Questions

What does minify mean in simple terms?

It means removing everything a browser does not need to read your code, such as spaces, line breaks and comments. The site looks and works the same, but the files are smaller.

Will minifying break my website?

Usually not, but occasionally a script or style stops working, most often when files are also combined. Test your menus, forms and checkout afterwards, and exclude any file that causes trouble.

Is minifying the same as compressing?

No. Minifying changes the file itself to make it smaller, while compression (such as gzip or Brotli) shrinks the file while it travels from the server to the browser. Using both gives the best result.

Can I minify files from other companies, like a chat widget?

No, those files are hosted and controlled by the provider, so you cannot edit them. You can remove the widget if you do not need it, or ask the provider whether a lighter version exists.

How much faster will my site be after minifying?

It depends on how large and how unminified your files are. The gain is usually modest on its own, so treat it as one step alongside image, compression and caching fixes.

Do I need a developer to minify CSS and JavaScript?

Often you do not. On many platforms a plugin or setting does it for you. A developer is useful for custom-coded sites, or when minifying causes something to break.

Related problems