How to enable Output Compression and remove unnecessary data from your HTML document

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 load longer and take much more of your bandwidth and you don’t want any of that.

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 WP installation and politely ask WP to do so.

There are two ways of enabling Output Compression. In this article, we’re about to show you how to enable it via .htaccess file:

    1. Open .htaccess file
    2. Copy and paste the following code:
# Insert filters
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/x-httpd-php
AddOutputFilterByType DEFLATE application/x-httpd-fastphp
AddOutputFilterByType DEFLATE image/svg+xml

# Drop problematic browsers
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html

# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary
  1. Save changes

After you’re done with changes, you are also done with enabling Output Compression which will make your HTML documents much more lighter.

If you don’t like this method, you can do the same by using PHP code.

START YOUR OWN BLOG

This guide is an introduction to mastering the art of blogging. It provides easy to follow steps to start, maintain, and grow your blog.

Read the guide

Leave a Reply

Your email address will not be published. Required fields are marked *