Client performance: adding gzip compression

Июнь 6, 2011

As a continuation of client side optimization let’s now find out how enabling gzip compression between server and client affects page loading.

First, one needs to enable mod_gzip for Apache (I’m using it) and configure it the proper way. Usually it’s reasonable to compress text content such as css or js files, as well as html response. Compressing images is usually considered as waste of CPU, so we should not allow it.

Here is my mod_gzip configuration file (thanks to this post):


mod_gzip_on                   Yes
mod_gzip_can_negotiate        Yes
mod_gzip_static_suffix        .gz
AddEncoding              gzip .gz
mod_gzip_update_static        No
mod_gzip_command_version      '/mod_gzip_status'
mod_gzip_temp_dir             /tmp
mod_gzip_keep_workfiles       No
mod_gzip_minimum_file_size    300
mod_gzip_maximum_file_size    500000
mod_gzip_maximum_inmem_size   60000
mod_gzip_min_http             1000
mod_gzip_handle_methods        GET POST
mod_gzip_dechunk              Yes
mod_gzip_send_vary            On

#Files and items to compress
mod_gzip_item_include         file       \.html$
mod_gzip_item_include         file       \.htm$
mod_gzip_item_include         file       \.js$
mod_gzip_item_include         file       \.js
mod_gzip_item_include         file       \.faces
mod_gzip_item_include         file       \.css$
mod_gzip_item_include         file       \.jsp$
mod_gzip_item_include         file       \.jsp

mod_gzip_item_include         uri        \.jsp$
mod_gzip_item_include         uri        \.jsp

mod_gzip_item_include         handler    \.*
mod_gzip_item_include         handler    \.*$

mod_gzip_item_include         mime       ^text/html$
mod_gzip_item_include         mime       ^text/html
mod_gzip_item_include         mime       ^text/plain
mod_gzip_item_include         mime       ^text/plain$
mod_gzip_item_include         mime       ^text/xml$
mod_gzip_item_include         mime       ^text/css$
mod_gzip_item_include         mime       ^text/javascript$
mod_gzip_item_include         mime       ^text/javascript
mod_gzip_item_include         mime       ^application/x-javascript$
mod_gzip_item_include         mime       ^application/javascript$

also this file has to be included in the apache configuration file by using the Include statement. To make a django application sending compressed response, the middleware list must contain django.middleware.gzip.GZipMiddleware in settings.py:

MIDDLEWARE_CLASSES = (
	'django.middleware.gzip.GZipMiddleware',
        'django.middleware.common.CommonMiddleware',
...
)

After doing that a Firebug can be used to see that content is compressed by the response headers:

ffgzip

Now lets run TestWebPage against my key pages from the previous post:

Before gzip

http://gdestop.ru:

gdestop-cdn

http://gdestop.ru/adler:

adler-cdn

http://gdestop.ru/anapa/view/492:

hotel-cdn

After gzip:

http://gdestop.ru:

gdestop

http://gdestop.ru/adler:

adler

http://gdestop.ru/anapa/view/492:

hotel

So, we have very good results for the root page, and resort’s page. Hotel’s page did get such a good boost because when I moved all common scripts to CDN, they became compressed by CDN.

  • ffgzip
  • gdestop
  • adler
  • hotel

posted in gdestop.ru, Optimization by dmitko

 
Powered by Wordpress and MySQL. Theme by Shlomi Noach, openark.org