Bookmark and Share

Reasons to improve page speed

There are some rumors on the web that page-rank might soon be influenced by the quality of the web page, among other factors also output compression and caching.

Additionally, users are not willing to wait for long responses, so quick delivery of a page is a must-have for any website.

mod_deflate

The Apache Module mod_deflate offers options to compress the http response. Some older browsers do not support compression under certain conditions (such as for css files or other external resources). Also there are problems with pdfs files in internet explorer, as the content is directly sent to the PDF reader instead of decompressing it first.

Enabling mod_deflate is quite easy. Either directly in .htaccess or more generally in httpd.conf. A valid example is the following, see the mod_deflate documentation for further details:

<IfModule mod_deflate.c>
        # enable compression
        SetOutputFilter DEFLATE
        # exclude old browsers
        BrowserMatch ^Mozilla/4 gzip-only-text/html
        BrowserMatch ^Mozilla/4\.0[678] no-gzip
        BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
        # exclude certain file types
        SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png|pdf|zip|exe|msi)$ no-gzip dont-vary
        <IfModule mod_headers.c>
                # fine tune caching at proxy servers
                Header append Vary User-Agent env=!dont-vary
        </IfModule>
</IfModule>

mod_expires

Browser caching of external resources can increase loading time of a web page and decrease server load. Browser caching should be used for static resources such as pictures, css files etc.

Enabling cache expiration can be done with the Apache module mod_expires, either with an entry in .htaccess or the server's httpd.conf. Cache times need to be entered in seconds:

<IfModule mod_expires.c>
        ExpiresActive On
        ExpiresByType image/jpg A3456000
        ExpiresByType image/jpeg A3456000
        ExpiresByType image/gif A3456000
        ExpiresByType image/png A3456000
        ExpiresByType text/css A604800
        ExpiresByType text/js A604800
</IfModule>