fbpx
Minify JavaScript CSS and HTML

Top Ways to Minify CSS, JavaScript, and HTML Files in WordPress

While you minify CSS, JavaScript, and HTML Files of your WordPress, you are actually reducing the loading speed of your website. Minification won’t reduce your Website’s loading speed to 50%. However, even a slight reduction will help boost website performance and positive change in search engine ranking.

Minification is a risky process that can break your site if not executed properly. So, before you start the minification of CSS, JavaScript, and HTML, you need to first understand what minification actually is.

What is Minification? : The Definition

You might have seen the term ‘Mininify’ while performing website performance tests on online tools like Google PageSpeed Insights and GTmetrix. However, have you ever thought about what it actually means?

Minification is the process of removing white spaces, lines, and irrelevant characters from the code to reduce the file size. This, as a result, reduces the website’s loading speed.

Generally, the minification is done on the files like CSS, HTML, and JavaScript. You can also minify PHP files but there won’t be any gain from it.

Minification of CSS Code

While doing minification of CSS code, the developers remove blank spaces and comments from it.

Below is an example of normal CSS code

body {
margin:20px;
padding:20px;
color:#333333;
background:#f7f7f7;
}
h1 {
font-size:32px;
color#222222;
margin-bottom:10px;
}

The CSS code after minification would look like this:

body{margin:20px;padding:20px;color:#333;background:#f7f7f7}h1{font-size:32px;margin-bottom:10px}

Minification of JavaScript

JavaScript is a widely utilized scripting language. It is commonly used by web developers for dynamic HTML output.

Normal JavaScript code before minification:

 function pentah() {
  var Ein  = document.getElementById('Ein');
  var Er = Ein.value * Ein.value;
  alert("Hello" + Ein.value + " = " + Er);
  Ein.value = 0;
 }

var pos = document.getElementById('pos');
pos.addEventListener ('click', pentah, true);

JavaScript code after minification:

 function pentah() { var Ein = document.getElementById('Ein'); var Er = Ein.value * Ein.value; alert("Hello" + Ein.value + " = " + Er); Ein.value = 0; }var pos = document.getElementById('pos');pos.addEventListener ('click', pentah, true); 

Minification of HTML

HTML or Hypertext Markup Language is a basic foundation of a website. It plays an important role in structuring information on a particular webpage.

A basic HTML code will look similar to this

<div class="wrapper">
 
  <div data-text></div>
  <span class="item">web developer</span>
  <span class="item">Software developer</span>
  <span class="item">SEO executive</span>

  <h2>I'm Rohan</h2>
 
</div>

After applying minification on HTML code, it will look like this:

<div class=wrapper>
<div data-text></div>
<span class=item>Web developer</span>
<span class=item>Software developer</span>
<span class=item>SEO executive</span>
<h2>I'm Rohan</h2>
</div>

Why Minify CSS, JavaScript and HTML?

As we explained at the beginning of this article that minifying will help in reducing file size and thereby boost website performance. Faster loading speed enhances UX and SEO.

Additionally, Minification minimizes the cost of bandwidth as minimal data is transmitted over the network.

Website Speed Test Check

On the web, you can find numerous tools to run a website speed test. However, we suggest that you try the GTmetrix speed test to check whether your website code is minified or not.

speed test minification
GTmetrix Minification

In the above example, you can see GTmetrix suggests all the files that need compression.

Methods to Minify CSS, JavaScript, and HTML

There are numerous ways to minify CSS, JavaScript, and HTML

  • Manual Minification Method
  • Use a WordPress Minify Plugin

Manual Minification Method

The manual minification method is only recommended to the users who have some coding knowledge and know what they are doing.

You need to manually replace the minified code with the original code.

The first step is to search for the code that needs to be compressed.

Head over to Google PageSpeed Insights or Gtmetrix to find out the code file that needs compression

The next step is to download the minified version of the code.

The last step is to upload the minified version which you have downloaded from the Gtmetrix. Now, replace the minified file with the source code. To replace the files, you can make use of an FTP Client or the cPanel website management tool.

Also Read: How to use FTP to upload files to WordPress

Alternatively, you can use tools like JavaScript Minifier (tool to minify javascript), CSS Minifier (tool to minify CSS), Minify Code (tool to minify HTML).

Next, let’s discuss how to minify CSS, JavaScript, and HTML in WordPress using plugin.

How to Minify CSS, JavaScript and HTML In WordPress Using Plugin

Earlier, we mentioned the manual method for minification which isn’t beginner-friendly. However, the second method we will discuss is the use of WordPress plugins. Hence, even a beginner can execute this method.

WordPress library is so big that you can easily find several plugins that can minify your website codes with just a few clicks. Moreover, some of the best caching plugins also have minification. Make use of it to minify your website codes.

Meanwhile, if you are looking to clear the cache of your WordPress site, you can check out the best web caching solution for your website.

Though you can find several tools for minifying, we suggest you use the best WordPress Minify plugins i.e: Autoptimize

Autoptimize

autoptimize
Autoptimize

Autoptimize is definitely the best WordPress Minify plugin you can go for. The plugin is quite simple to use and packs several robust features that can improve your performance drastically.

Even the size of this plugin is relatively smaller than other plugins. The Autoptimize plugin is beneficial in aggregating scripts. Besides having several website optimization features, this plugin has an option to minify HTML, CSS, and JavaScript.

Use this plugin to reduce the file size by up to 50%.

Conclusion

In this article, two methods for minification were explained:

  • Manual minification method
  • Minification using the plugin.

We hope, know you understand how to minify the JavaScript, CSS, and HTML files of your WordPress site to improve your website speed. 

Additionally, you can check out our Managed WordPress Hosting plans that offer high-speed SSD storage for extreme speed for optimal website performance.

Feel free to express your queries in the comment section.

Our Experts will help you build the right solution or find the right partner for your needs.

Google Workspace

Business email solution at a discounted price. Unlock the best offer now!

49/mo

Business Email

Business email solution at a discounted price. Unlock the best offer now!

49/mo

Microsoft 365

Business email solution at a discounted price. Unlock the best offer now!

49/mo

SSL Certificate

Get a massive discount on SSL Certificate to secure your website.

725.46/mo

Bit Ninja

Get a massive discount on SSL Certificate to secure your website.

725.46/mo

Acronis Cloud Backup

Get a massive discount on SSL Certificate to secure your website.

725.46/mo

Domain Name Search

Check out the best deal for domain registration. Get your domain now!

399/mo

Domain Transfer

Check out the best deal for domain registration. Get your domain now!

399/mo

Bulk Domain Search

Check out the best deal for domain registration. Get your domain now!

399/mo