Compressing your content saves bandwidth and improves render time, particularly on devices with slow internet connections but it also reduces load on your server. While it does take some amount of computer power to compress files on the fly, you save much more power by having your server doing fewer things at once. It takes a lot less time to transfer files that are smaller. Your server is therefore, at any given time, maintaining far fewer open connections. There really is no down-side to enabling some form of HTTP compression.
If you don’t have GZIP compression enabled, there are a couple ways you can go about enabling it on your webserver.
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
The second way to enable Gzip compression is by editing your .htaccess file. Most shared hosts use Apache, in which you can simply add the code below to your .htaccess file. You can find your .htaccess file at the root of your WordPress site via FTP.
Ensure to add the these lines at the bottom of the .htaccess file.
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE font/opentype
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
# Remove browser bugs (only needed for really old browsers)
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0 no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent
if the above methods are not worked, simply add this line to the top of your PHP documents:
<? ob_start("ob_gzhandler"); ?>
It has to be inserted before any content is outputted. It’s not as efficient as mod_deflate, but it still works well and saves a ton of bandwidth and processor power.
And that’s it!
You can test the result directly with your browser developer’s tool (inspector), or by using some online tools such as: HTTP Compression Test. Just enter your site’s URL, and it will tell you if it is actually gzipped, and if it is, you will see the impressive compression ratio.