How to Minify HTML, CSS or JavaScript in WordPress

Wouldn’t it be great if your site performed better, if only a little faster? To make a difference, you need to learn how to minify HTML or other files in WordPress.

In this article, we will explain how to minify CSS, HTML, and files in WordPress to ensure the best possible performance.

Why is it important to minify your files?

If you’ve ever looked at an HTML, CSS, or JavaScript file, you’ve probably noticed a lot of white space or line breaks. These characters make the code easier to read, but the files that contain them will be larger and slower to load.

This is why WordPress minification is crucial for those who have a site. The process removes unnecessary whitespace, lines, and characters from the code, resulting in more compact data.

Although many experts argue that minification doesn’t make much of a difference, we highly recommend it. You have to squeeze every bit of optimization you can get to improve the user experience. After all, even a fraction of a second matters.

Two simple ways to minify files

You can minify your WordPress resources manually or use a plugin. Read on to find out what is best for you.

Minify files manually

When we say “manually”, it doesn’t mean that you have to remove the unnecessary characters by yourself. There are many useful tools that can speed up the process. However, you do need to upload the minified files to your site afterward, so keep that in mind when following this guide.

  1. Locate the files you want to minify using . Enter the URL of your website and the tool will show you the files that you can optimize.
  2. click on See Optimized Version to download the minified versions.
  3. Use a FTP client to overwrite the original files in your site directory with the minified versions. You can also use the hPanel file manager.
See also  How to disable Selinux in CentOS 7 (Disable Selinux)

Alternatively, you can use , a WordPress minification tool to minify HTML, CSS, and JavaScript separately:

  1. Download the files you want to minify from your website. Keep a copy as a backup.
  2. Copy the content of the file and paste it into the appropriate minification tool.
  3. Once done, paste the code in the downloaded file and upload it to your website directory.

If you want to avoid dealing with the code, check out the second method below.

Use a WordPress minification plugin

Using a WordPress minification plugin is much easier as the tool will minify your files automatically. Here are our top picks for doing it, selected based on features and ease of use:

  • minify your JavaScript and CSS files using PHP Minify. You can even ask the developer to set custom optimization options for the plugin.
  • makes sure minifications don’t affect your theme or other plugins. In addition, the plugin also provides many convenient features such as integration and multisite support.
  • is a WordPress minification plugin that can minify, merge and cache your site files. In addition, it is one of the simplest and lightest tools available.

Whichever plugin you choose, all you have to do is choose the files you want to minify and the tool will work in the background.

However, since those plugins offer other features, it would be great if you tried them all to see which one brings you the most value.

Check changes after minification

Be sure to check that you have fully optimized your site using GTMetrix. The tool will score the size of your files and show any unresolved issues.

See also  WooCommerce vs Shopify: Detail and Comparison

For example, our test shows that we got a CSS score of 99, with two files that could be further improved:

With those issues fixed, we got a perfect score of 100:

conclusion

Minifying HTML, CSS, or JavaScript files in WordPress is a handy optimization that can improve the performance of your website. And the best thing is that anyone can do it without problems.

Let’s take a look once again at how to minify WordPress files:

  • Minimize files manually: use to download the optimized files or shorten the content using . Then replace the files in your website directory with the new ones.
  • Use a WordPress minification plugin: Install one of the plugins we recommend and adjust the settings according to your preferences. The tool will take care of the rest.

Once you’re done, make sure you get a perfect score in GTMetrix.

Let us know in the comment section if you have any problems.

Gustavo is passionate about creating websites. He focuses on the application of SEO strategies at for Spain and Latin America, as well as the creation of high-level content. When he is not applying new WordPress tricks you can find him playing the guitar, traveling or taking an online course.

Loading Facebook Comments ...
Loading Disqus Comments ...