|
How To Compress Content Served By Dekoh
How do I Compress Content Served by Dekoh ApplicationsCompressing documents served by web servers results in accelerated user experience. You can find some good documents in 1 ,2 .
In this How To, you will see how a Dekoh application can compress the content it serves. Dekoh Web server ships a javax.servlet.Filter which can be configured to compress responses served by any web application. Assuming your Dekoh application is a Java Web application, to configure the CompressionFilter, the following entries needs to be made in the standard deployment descriptor, web.xml.
<filter-mapping>
<filter-name>CompressionFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>CompressionFilter</filter-name>
<url-pattern>*.js</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>CompressionFilter</filter-name>
<url-pattern>*.css</url-pattern>
</filter-mapping>
For your convenience, the filter with the name CompressionFilter has been implicitly defined in Dekoh's Web server and you need not declare this again in your application's web.xml. This filter definition is contained in <DekohInstallDir>/server/nodes/default/config/default-web.xml. The code is reproduced below.
<filter>
<filter-name>CompressionFilter</filter-name>
<filter-class>com.pramati.web.util.filters.CompressionFilter</filter-class>
<!--whether to enable debug or not. a value greater than 0, logs messages in server logs.-->
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<!--size of the file (in kb), should be larger than the size mentioned, for compression to happen. if set to -1
compression will never happen. if set to 0, compression will happen for matching url pattern-->
<init-param>
<param-name>compressionThresholdKb</param-name>
<param-value>5</param-value>
</init-param>
</filter>
By putting in the above filter mappings in the application's web.xml, responses (of size > 5kb) to URLs that end with jsp,js,css are GZip compressed when the request is made by a browser that can decipher compressed responses. The filter mappings can be changed such that CompressionFilter is applied on responses to different URL patterns like static/*. Dekoh applications can override the definition of CompressionFilter to supply another value for init-param compressionThresholdKb. Since the class file of CompressionFilter is supplied by Dekoh web server, you need not package it with your Dekoh applications. |