Compressing file is now essential in optimizing website so the transferred file size can be reduced and significantly make the page loads faster. This is obvious, by using GZIP or Mod Deflate File Compression the file can be minimized from 60% - 80% from the original size. Off course it should make your website/ blog load 2 - 3 times faster.
Based on my own oxperience where my webhosting does not activate the mod_deflate on its server, so I forcibly had to use gzip compression as solution. Compared to GZIP mod, mod_deflate can compress almost all files transferred from a web server, like all kinds of images, javascripts, and html itself. If you are lucky, you can activate this mod_deflate from your Cpanel, find Software / Service – choose Optimize Website and compress all content. Or alternatively you can also add the following codes to your .htacces, in your web root directory:
# Compress text, html, javascript, css, xml:If your hosting does not activate or support the mod_deflate, alternatively you can try using http GZIP compression. This gzip compression is actually has a better compression ability compared to mod deflate, where the compression ratio is around 70% - 80%. This means from every 100kb file, the compressed file will be just 30kb to 20kb only. To apply this gzip compression, add the following code to header.php in your theme as example below:
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
# End compression
<?phpBut please note, if your wordpress theme uses page template (page.php), it is no recommended to put the code on header. The code must be placed in the following files: index.php, single.php, page.php, archive.php and 404.php. Apply the code like this:
if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')
{ob_start("ob_gzhandler");}
else {ob_start();}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> so on so forth...
<?phpIf you have placed it correctly, your page size should be smaller and loads dramatically faster. But keep in mind that the compression only applied to file created by php. It won't works for javascripts, css and images. Alternatively, you can also try the simpler and easiest way to compress your wordpress site, see how to do it in Easiest http compression Tips – Without Plugin.
if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) {
ob_start("ob_gzhandler");
}
else {
ob_start();
}
?>
<?php get_header(); ?>