Saturday, August 23, 2008

There are many articles on the web about how to improve performance of website running on apache webserver. But I summarize here, so that you can start directly using them:
  1. Remove all 404 file references
  2. Remove duplicate javascript and css references
  3. Remove unnecessary images
  4. Minify all javascripts and css. There are many tools available to do this, but my personal favourite is YUI Compressor
  5. Enabling gzip compression. To do this you need to make some changes in apache configuration file(httpd.conf but you can also do it in .htaccess file). To enable gzip compression in apache enable module mod_deflate in httpd.conf. you can do this by removing semicolon before this entry LoadModule deflate_module modules/mod_deflate.so

    Add following entry at the end of the httpd.conf:


    SetOutputFilter DEFLATE
    SetInputFilter DEFLATE

    # Netscape 4.x has some problems...
    BrowserMatch ^Mozilla/4 gzip-only-text/html
    # Netscape 4.06-4.08 have some more problems
    BrowserMatch ^Mozilla/4\.0[678] no-gzip
    # MSIE masquerades as Netscape, but it is fine
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

    # NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
    # the above regex won't work. You can use the following
    # workaround to get the desired effect:
    BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html

    # Make sure proxies don't deliver the wrong content
    #Header append Vary User-Agent env=!dont-vary


    # The two lines above compress everything unless excluded below.
    SetEnvIfNoCase Request_URI \.(?:gif|jpeg|png|jpg)$ no-gzip dont-vary
    SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary
    SetEnvIfNoCase Request_URI \.pdf$ no-gzip dont-vary
    SetEnvIfNoCase Request_URI \.avi$ no-gzip dont-vary
    SetEnvIfNoCase Request_URI \.mov$ no-gzip dont-vary
    SetEnvIfNoCase Request_URI \.mp3$ no-gzip dont-vary
    SetEnvIfNoCase Request_URI \.mp4$ no-gzip dont-vary
    SetEnvIfNoCase Request_URI \.rm$ no-gzip dont-vary
    SetEnvIfNoCase Request_URI \.plist$ no-gzip dont-vary
    SetEnvIfNoCase Request_URI \.swf$ no-gzip dont-vary
    # Below is an example where you get rid of what's above and you explicity compress.
    AddOutputFilterByType DEFLATE application/x-httpd-php application/x-httpd- fastphp application/x-httpd-eruby text/html text/javascript

    DeflateFilterNote ratio
    DeflateCompressionLevel 9


    There are still many things that should be done to improve site performance. I will write about them in my next article.

Hope this helps

No comments: