Minification in WordPress: What it Is and How to Do It

  by Jason Cosper
Minification in WordPress: What it Is and How to Do It thumbnail

As you add more tools and content to your site, the number of files will expand, leading to slower loading times. Speed matters on the internet, so a slow-loading site can be a big problem.

One way you can combat this problem is through minification. This is the process of compressing certain files (such as CSS, JavaScript, and HTML files) to shrink their size without impacting their functionality. The best part is you don’t even need any coding know-how to minify these files!

What is minification in WordPress?

Minification in WordPress is the process of removing unnecessary characters (line breaks, spaces, and comments) from your site’s CSS, JavaScript, and HTML files. The code works exactly the same, but the files get smaller, so browsers download and process them faster and your pages load sooner.

Why does that matter? Every second counts on the internet. As far back as September 2009, research conducted by Forrester Research for Akamai found that 47% of consumers expect an ecommerce page to load in two seconds or less.

Speed also affects your bottom line. Akamai’s Online Retail Performance Report (April 2017) found that a 100-millisecond delay in website load time can hurt conversion rates by up to 7%. Fortunately, there are remedies to help you speed up your site, including minification.

You may not realize it, but many of the files that keep your site running can also be slowing it down. Minification tackles that by cleaning up the code itself.

One quick distinction: minification isn’t the same as Gzip or Brotli compression. Compression happens on the server, shrinking files in transit before the browser unpacks them. Minification permanently removes characters the browser never needed in the first place. The two stack rather than compete (a minified file compresses even smaller), so use both.

This minification process may sound overly technical on the surface, but it’s very straightforward. It simply involves removing unnecessary characters from the code.

Let’s look at an example. Here’s what a normal CSS snippet might look like:

#bluetext {
font-size: 2em;
color: blue;
}
#redtext {
font-size: 1em;
color: red;
}

If you were to minify this code, the result might end up looking like this:

#bluetext{font-size:2em;color:blue;}#redtext{font-size:1em;color:red;}

All of the required information is still there, but the line breaks, spaces, and some other characters have been removed. These elements are not necessary for a computer to understand the code and only exist to make it more readable to humans.

It may not seem like this minor change would have a big effect, but think about how many lines of code you have running under your site’s hood. Minification trims the size of each file, which helps your site load faster. Be honest with your expectations, though: on its own, minification usually shaves a modest amount off load times — think a few percentage points, not a transformation. It works best as one tactic in a broader speed stack alongside caching, image optimization, and a CDN.

We’re now going to look at two methods you can use to minify code, both manually and with a dedicated plugin.

Subscribe now to receive all the latest updates, delivered directly to your inbox.

How to minify CSS, JavaScript, and HTML manually

Manual minification lets you quickly compress CSS and JavaScript code using a dedicated application. This enables you to write code that’s easy to read and interpret first, before minifying it with a tool in seconds.

To start minifying CSS, we recommend using a tool such as Toptal’s CSS Minifier, CSS Minify, or Clean CSS. With JavaScript, Minify can be a good starting point. However, there are alternatives such as JSCompress and Toptal’s JavaScript Minifier. And don’t forget your markup: Toptal’s HTML Minifier handles HTML the same way — paste in your code and copy out the minified version.

Fortunately, the tools will all work in the same way. For example, using Clean CSS, you’ll just need to paste your original code into the relevant field and click on CSS Minify. You’ll see the results in the other field, which you can then copy and paste into your site:

minify your CSS files in WordPress

We recommend saving both versions of the code. Otherwise, you risk losing the original code. The original will be easier to troubleshoot and edit than the minified version.

Additionally, we recommend that you only use manual minification if you are confident in your coding abilities. If you don’t have a lot of experience, you might want to use a WordPress minification plugin instead.

The best WordPress minify plugins

The short answer: pick Autoptimize if you want a beginner-friendly, ‘set and forget’ option, pick Fast Velocity Minify if you’re comfortable testing and tuning settings for your site, and pick WP-Optimize if you’d rather have minification bundled with caching and database cleanup in a single plugin.

Whichever you choose, since these files are so vulnerable, you’ll want to make sure that you use a plugin that’s trusted and safe. And because results vary from site to site, run a speed test such as Google’s PageSpeed Insights before and after trying each plugin, and keep the one that measurably helps.

1. Fast Velocity Minify

Fast Velocity Minify

Fast Velocity Minify is a powerful HTML, CSS, and JavaScript optimization plugin aimed at developers and advanced users. The developer’s guidance is to open the HELP tab after installing and configure the plugin for your specific site: each site is different, so the default recommendations may or may not work for you. In exchange for that setup work, it provides a huge amount of options if you want to tinker with the specifics.

Key features:

  • Configurable per site via a detailed HELP tab (manual setup recommended by the developer)
  • Offers extensive options for advanced users
  • Provides great results and reliable support

Pricing: Fast Velocity Minify is open-source and completely free.

2. Autoptimize

WordPress Autoptimize plugin for minifying files and speeding up WordPress website

Autoptimize is one of the more popular minification plugins (and for good reason). It can aggregate (bundle) your files, minify them, and cache them, although the plugin’s FAQ notes that new installations no longer aggregate CSS and JS files by default, since HTTP/2 made combining files less important. While it does offer some additional options, this plugin is ideal for those who want a ‘set and forget’ approach to minification.

Key features:

  • Easy for beginners to grasp
  • Additional options for more optimized performance
  • Advanced customization using the dedicated API

Pricing: The Autoptimize plugin is free; a premium Autoptimize Pro subscription adds image optimization, a CDN, page caching, and critical CSS, and the developers also offer performance-optimization services.

3. WP-Optimize

WP-Optimize is an all-in-one performance plugin trusted by more than 1 million WordPress sites. Minification is one of its four core features, alongside page caching, image compression, and database cleanup — a good fit if you’d rather manage your whole speed stack from one plugin instead of several.

Key features:

  • Minifies CSS and JavaScript alongside one-click page caching
  • Compresses images, with WebP conversion
  • Cleans and optimizes the WordPress database on a schedule

Pricing: The core WP-Optimize plugin is free; a premium version adds features such as lazy loading and more flexible clean-up scheduling.

Our verdict: start with Autoptimize. Move to Fast Velocity Minify if you need finer control and don’t mind configuring it, or to WP-Optimize if you want minification, caching, and cleanup handled together.

How to Minify WordPress Files With a Plugin

Now that you’re familiar with the tools available, you can start minifying your WordPress files. If you’re a beginner, install Autoptimize, head to Settings > Autoptimize, and tick the options to optimize HTML, CSS, and JavaScript — that’s the whole setup. Below, we’ll walk through Fast Velocity Minify instead, the advanced-user pick, since its configure-and-test workflow teaches you what to watch for with any minification plugin.

Once you’ve installed and activated the plugin, open its HELP tab and review the settings for your site. The developer is upfront that every site is different: the default recommendations may or may not work for you, so test your site after enabling minification and adjust as needed.

The next time somebody visits your site, the plugin will intercept your files and create a copy of them. It will then group the files and minify their coding to cut down on the number of requests. These optimized files are saved in the cache and used whenever the site is accessed again. This means your original files will be unaffected.

If you’re a more experienced user, the plugin does offer some advanced settings. You can access them by going to Settings > Fast Velocity Minify within WordPress:

Fast Velocity Minify settings in WordPress

Among other options, you can disable minification for certain files, exclude specific assets from the process, and determine the cache’s location. You can also purge any minified files and allow code processing on specific query strings:

Fast Velocity Minify settings in WordPress

Treat the defaults as a starting point, not a finished setup. The developer’s own guidance is that each site is different, so the default recommendations may or may not work for you — test your site, check the plugin’s HELP tab, and adjust the settings until everything works.

Finally, confirm the plugin is actually doing its job: view your page’s source code and look for the minified files, then re-run a speed test such as Google’s PageSpeed Insights to compare your scores from before and after.

What to do if minification breaks your site

Minification occasionally breaks things. The usual symptoms are a mangled layout, missing icons or fonts, or interactive features (sliders, forms, menus) that stop responding, often with JavaScript errors in your browser’s developer console. It happens because some files don’t tolerate being minified or combined, or because scripts end up loading in the wrong order.

Here’s how to fix it without panic:

  1. Roll back first. Purge the plugin’s minified cache and temporarily turn off minification (or deactivate the plugin). Your original files are untouched, so your site returns to normal immediately.
  2. Find the offending file. Re-enable minification for CSS only, then JavaScript only, to see which side causes the problem. Then use the plugin’s exclusion (ignore) list to rule out half of the suspect files at a time until you’ve isolated the one that breaks.
  3. Exclude it and move on. Leave that file on the exclusion list, purge the cache again, and re-test. You keep the speed benefit on everything else while the fragile file loads as-is.

FAQs about minification in WordPress

Can minification break my WordPress site?

Occasionally, yes. Some CSS or JavaScript files don’t tolerate being minified or combined, which can break layouts or interactive features. Your original files are never modified, so you can recover by purging the plugin’s cache, excluding the problem file, or deactivating the plugin.

What’s the difference between minification and Gzip compression?

Minification permanently removes unneeded characters from a file. Gzip or Brotli compression shrinks the file during transfer and unpacks it in the browser. They stack: a minified file compresses even smaller, so use both.

Should I minify CSS, JavaScript, or HTML first?

Start with CSS and JavaScript — they’re usually the largest text files and deliver the biggest savings. HTML minification helps too, but the gains are smaller. Most WordPress plugins let you enable all three and test each one separately.

How do I undo minification?

Turn off the minification settings (or deactivate the plugin) and purge its cache. Minification plugins work on cached copies, so your original files are untouched and your site immediately serves them again.

Do I need a minification plugin if I already use a caching plugin or CDN?

Check first: many caching plugins and CDNs already minify CSS and JavaScript. Running two minification tools at once can cause conflicts, so enable it in one place only.

Minify Your WordPress Files Today

Minifying your WordPress files is a quick and simple way to improve your site’s performance.

This way, you can make sure that you don’t lose visitors due to long loading times.

It may seem like a technical nightmare to accomplish, but you don’t actually need technical knowledge of CSS or JavaScript to minify your WordPress files. A plugin like Autoptimize can do most of the work for you.

Ad background image

Do More with DreamPress

DreamPress managed WordPress hosting bakes speed in: a built-in caching stack, free Bunny CDN, 1-click staging, and daily backups on every plan.

Check Out Plans

Jason is DreamHost’s WordPress Product Advocate, based out of Bakersfield, CA. He is currently working on making our DreamPress product even better. In his free time, he likes to curl up on the couch and watch scary movies with his wife Sarah and three very small dogs. Follow him on Twitter.