SEO Soul

Sold my soul to SEO

Archive for the 'Web design' Category

Using mod_gzip to optimize a website

mod_gzip is an Apache web server module that compress HTML code saving bandwidth - usually around 50-80% - and speeding up the time to load the web pages.

mod_gzip is supported by the vast majority of web browsers. Anyway, if it’s not supported by the web, HTML code is sent without compression, so we have not to worry about compatibility in the client-side.

Checking our server

In order to set up mod_gzip compression for our website we need Apache webserver (standard in Linux servers) with mod_gzip module loaded. We can check it this way:

- Create a file named info.php containing the following:

<?php
phpinfo();
?>

- Now we upload that file to our website’s root directory and load it in the web browser. If the module is enabled, we should read a line like this:

_SERVER["HTTP_ACCEPT_ENCODING"] : gzip,deflate

How to activate mod_gzip

It’s very simple, we only need to call a PHP function (gzip_start.php) at the start of each PHP page and to another PHP function (gzip_end.php) at the end. We can do that even without editing the PHP files of the website using a custom php.ini file, copying that php.ini to every directory of the website. It’s as easy as adding these lines to it:

auto_prepend_file = gzip_start.php
auto_append_file = gzip_end.php

Now we have to create the files gzip_start.php and gzip_end.php and upload to the root directory of the website:

  • gzip_start.php containing: <?php ob_start(”ob_gzhandler”);?>
  • gzip_end.php containing: <?php ob_flush();?>

That’s all.

Possible problem with captchas

There is a possible problem with captcha images. As the code is sent compressed, captcha image will be erroneus. We can solve this placing in the captcha’s php directory a php.ini config file that does not include auto_prepend_file and auto_append_file.

Checking

Now we should check if mod_gzip is running fine.

No comments