Blog

Enabling Compression for Your Website & Why It Matters



Compressing your files before serving them to your viewers is key for Search Engine Optimization (SEO). By compressing your files, you are essentially optimizing your viewers experience, and search engines like Google, prefer that.

In addition to SEO performance, it also provides other great benefits:

  • Faster page loading for your visitors
  • Less data transfer used on your web hosting account

"By compressing your files, you are essentially optimizing your viewers experience, and search engines like Google, prefer that."

Considerations

Before you begin, this assumes you have mod_deflate enabled. Typically most cPanel installations, or shared web hosts will already have mod_deflate enabled.


Compressing HTML & Content

To compress HTML, Javascript, Image, and CSS files, your web server Apache will use a module called mod_deflate. Normally you can easily enable Gzip compression using mod_deflate by adding the following lines to your .htaccess file:

<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/x-javascript
</IfModule>

Make sure you place your .htaccess file in the root of your HTML directory (typically, public_html). Try to refresh your page to make sure the changes worked. If you get an error, mod_deflate is likely disabled and you will need to enable it or ask your Web Host to enable it for you.


Compressing PHP Files

The above will encode any html, xml, css and javascript files. The next step is to enable compression for PHP files by changing the following lines in your php.ini file

output_handler = Off
zlib.output_compression = On

Your php.ini file may be edited in your cPanel control panel. Search for "MultiPHP INI Editor", otherwise you can place the file directly in your HTML directory.


Testing

Once you have restarted saved your configuration files and restarted Apache, you can now test your sites compression. We recommend using https://checkgzipcompression.com/ to check if your site has compression enabled.



Recent Posts