Once you install WordPress and start creating documents which you want to present to your visitors, you might start worrying about the size of your HTML files. As you might already know, even blank spaces, carriage returns, new lines, and tabs take some space. That means a document will take some extra time loading and it will take much more of your bandwidth; that’s something you want to avoid at any costs.
That’s where Output Compression comes as a hero. Because WordPress does not compress files this way on its own, it’s your task to make a conversation with your WordPress system and politely ask it to start compressing.
There are two ways of enabling Output Compression. In this article, we’re about to show you how to:
How to enable Output Compression and remove unnecessary data from your HTML document
If you aren’t stranger to the .htaccess file in WordPress, this method shouldn’t be a problem.
- Open .htaccess file
- Copy and paste the following code:
- Save changes
After you’re done with changes, you are also done with enabling Output Compression which will make your HTML documents much lighter. This simple task will speed up your site, so don’t be afraid of completing the steps.
How to enable Output Compression in WordPress using PHP
If you don’t like the .htaccess method or you aren’t comfortable enough around the file, you can leave the same job to always trustworthy PHP. We all know how powerful PHP is, so handling Output Compression shouldn’t be a difficult task for it. And it isn’t.
A single line of code in index.php file will do the trick:
- Locate the root directory of your WordPress installation
- Navigate to index.php and open the file
- Copy and Paste the following code on top of the document:
But, allowing this piece of code to do its magic takes one more step. And that is enabling it in php.ini file. Don’t worry; it’s not a big deal. You will need this line of code:
Set zlib.output_compression = On
You can change the level of compression by using and altering the number in the following function:
zlib.output_compression_level = d
“d” can be any number from 1-9 where 1 represents the lowest level of compression and 9 the highest one.
Enabling output compression in WordPress is as easy as copying and pasting the functions. Still, if you’re not sure about the code or tampering the files, we suggest that you leave the compression to WordPress plugins. After that, you might be interested in clearing and optimizing the WordPress database.
Don’t forget that speeding up a site is an ongoing job, so make time for the optimization of your site on a monthly basis.