GZiping text files using Apache Http Server

In most of the enterprise installation the request made by browser first goes to Http Server and then Http Server forwards that request to the J2EE Server such as IBM WebSphere Application Server, WebSphere Portal Server or WebSphere Commerce server.

If you have a Http Server in between your browser and Application Server, then you can configure it to compress the response before sending it back to the Browser. YOu can configure Http Server to configure not only the static text files that are hosted on Http Server such as CSS and JavaScript files but it can also configure the dynamic Html files created by Application server like this.

One of the advantage of this approach is that your application server does not have to know anything about GZIP and you can simply configure Http Server to decide what type of files to compress, enable compression trace, exclude browsers that bugs from compression, exclude URL's or file extensions that should be excluded from compression, configure your proxy to handle compression.

The Apache Http Server(IBM Http Server is based on Apache Http Server) has mod_deflate module that can be used to configure compression.

You can enable Http Compression at Apache level by opening HTTPServerRoot/conf/httpd.conf and adding these lines to it

LoadModule deflate_module modules/mod_deflate.so
AddOutputFilterByType DEFLATE text/html text/plain text/xml

The AddOutputFilterByType directive activates a particular output filter for a request depending on the response MIME-type. In our example it is applying mod_deflate to response where content-type is either text/html, text/plain or text/xml. The DEFLATE filter will compress the output before sending it to the client.

Enabling filters with AddOutputFilterByType may fail partially or completely in some cases. For example, no filters are applied if the MIME-type could not be determined and falls back to the DefaultType setting, even if the DefaultType is the same. SO there is another more complex and powerful way in which we can configure mod_deflate

<Location />
# Insert filter
SetOutputFilter 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

# Don't compress images
SetEnvIfNoCase Request_URI \
\.(?:gif|jpe?g|png)$ no-gzip dont-vary

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

1 comment:

Anonymous said...

Hi ,

I had a doubt. i am using websphere commerce server 6.0. i want to implement gzip in my project for css and js files. could u please tell me which configuration file i should make the change so that browser can understand about the encoding format.