blog posts

How to fix Minify HTML error in gtmetrix

In the previous session, we fixed the Avoid bad requests error in GTmetrix , which in most cases is one of the errors that occur in most of the tests that are done to check the speed of the site, and we learned how to find and fix the error. Now, in this tutorial, I am going to address how to fix the Minify HTML error in gtmetrix, by using this tutorial, you can minify pages in WordPress or any content management system. The meaning of Minify HTML is to make the pages of our site that are displayed in HTML format for the browser in such a way as to reduce its space as much as possible.

If you are familiar with HTML, an HTML document that we create, each part of this document has codes that we enter in each line, an example of which you can see below.

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>…</title>
</head>
<body>
.
.
.
</body>
</html>

 

As you can see in the example above, each part of the tags was arranged in a line so that it is readable for someone who is writing code and can easily separate and analyze the codes. But the bad thing about this method is that the empty spaces and frequent inters that we use to separate each section creates junk space that increases the size of the page, so it is better to come and reduce the total file size by putting the codes together. Even if the size of a file is reduced as little as possible. Of course, the issue is not only volume. In this case, another problem that exists is that when reading from the server and sending a request from a page, line by line must be checked, which makes it take longer to read all the lines and reach the end of that time. The sample code above can be entered in the form below, which is compressed and minified.

<html xmlns="http://www.w3.org/1999/xhtml"><head><title>…</title></head><body>...</body></html> 

How to fix Minify HTML error in gtmetrix

Well, so far I have explained by citing an example that the purpose of minifying a document in HTML is to write the codes in a summary form and avoid empty spaces that increase the volume and increase the reading time. Sometimes, some lines contain explanations that are useful for the developer, but not useful for the person who needs to view this document. This summary writing in the codes is not only for HTML language and you can improve the loading speed by optimizing it in other languages ​​as well. In general, minifying and reducing the size of html documents can exist in three possible modes.

1. Minify HTML for static sites

In this case, your site is designed without any CMS and you do not use a database. The only files you have include HTML, CSS, JavaScript, etc. documents, which are used for appearance design, and to minify them, just follow the same method as the above example. For this purpose, you can use online sites that you can access one of these sites by clicking on the button below.

minifycode.com

After entering this site, just copy the code in your HTML document and put it in the box of this site, similar to the image below.

Fixing the Minify HTML error in gtmetrix and increasing the speed of the site

After placing the codes, click on the Minify HTML button, your codes will be prepared in a compressed form and will be shown to you like the example below. By placing them in the HTML document, you can remove the empty spaces and non-useful description codes. Reduce the file size.

Fixing the Minify HTML error in gtmetrix and increasing the speed of the site

2. Minify HTML for dynamic sites

This method is useful for sites that use CMS for this purpose and the content of the site is available to users through the database. In this case, you don’t have an HTML file that you can use to optimize the codes in it in the above way. You might think that, for example, since WordPress is designed with PHP language, you can act in the same way and optimize the codes. But in this case it is wrong, because the php language is on the server side and reads data from the server and displays it to you. So, whether the codes are written in order or compressed, in any case, they have no effect on the final result provided to the user.

For this mode, you need to use compressor plugins. For this purpose, various plugins have been created, each of which gives you special features and facilities. But for this, I suggest you use a plugin that provides you with more features so that you can compress other files such as JavaScript and CSS in addition to minify WordPress html. Until today, I have introduced several plugins in the Hostfa knowledge base for this purpose. You can on how to install the wp rocket plugin to increase the speed of the site and training on compressing files in WordPress and increasing the speed of the site learn about and use these plugins .

3. Use of CDN

The previous two methods were such that you could optimize the files. But there is also a mode that by using this mode, in addition to compressing HTML files, CDN content distribution network. you also have the possibility to provide data to users on a platform which is available to them from the nearest server based on their geographical location. This can increase the speed of your site several times.

You can use cloudflare for this. Before doing anything, refer to the Cloud Flare training and set your domain’s DNS to Cloudflare. Then click on the SPEED option in the Cloudflare user panel, similar to the image below, and activate the three options javascript, css and HTML.

Fixing the Minify HTML error in gtmetrix and increasing the speed of the site

By activating this option, all the files of your site that are located on Cloudflare’s servers will be compressed and will be available in a shorter time and at a faster speed.

I hope that this tutorial has been of interest to you and that you were able to compress Minify HTML error files in WordPress or any other site builder and fix the Minify HTML error in gtmetrix. If you have any questions or problems related to this tutorial, let me know in the comments section so that I can answer you as soon as possible