About Nitin Kumar

Nitin Kumar works as a Solution Architecture in Wipro Technologies specialize in SOA. He has over twelve years of experience in information technology architecting and developing software systems, focus mainly on JEE solutions.

Improve Performance by caching and compression

Web page designs are becoming innovative with rich interface which involve extra code such as java scripts, css, and images etc. Most of the end-user response time tied-up in downloading these components.Optimizations of number of http requests and response size are the key parameters to improve the web application performance.

This article explains about caching filter and compression filter that are suitable for use with any web application to optimize number of request and response size.

Compressing Content Gzip Servlet Filter

 
HTTP Compression is a way to compress content transferred from servers to browsers which reduce the http response size. This standards-based method of delivering compressed content is built into HTTP/1.1, and all modern Web browsers support the HTTP/1.1 protocol, i.e. they can decode compressed files automatically at the client-side browser. The smaller the size of your information, the faster it can all be sent. Therefore, if you compress the content your web application, it will be displayed on the user’s screen faster.

Source Code:Download link OpenWebOptimizer for Gzip Servlet filter source code with sample code and usage document. 

Gzip is the most popular and effective compression method at this time. It was developed by the GNU project and standardized by RFC 1952. Gzipping generally reduces the response size by about 70%.

For adding the Gzip filter just adds below code into web.xml including attached Gzip filters

<filter>
<filter-name>GZIPFilter</filter-name>
<filter-class>com.opcat.gzip.GZIPFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>GZIPFilter</filter-name>
<url-pattern>*</url-pattern>
</filter-mapping>]]>

HTTP Servlet Caching:

Caching reduces number of HTTP request which makes web page faster. Web application generate browser content and in many scenario content won’t change between different requests therefore if you can cache the response ,you can reuse again without HTTP requests which improve the web application performance. We can achieve caching by just writing simple caching filter

Source Code: Download link OpenWebOptimizer for Caching Servlet filter source code with sample code and usage document.

Caching filter means a servlet that will intercept all requests and cache it and have a valid cached copy. The filter will immediately respond to the requests by sending a copy of cached contents. However, if no cache exists, the filter will pass the request on to its intended endpoint, and the response will be generated and cached for future request.

For adding the caching filter just add below code into web.xml

<filter>
<filter-name>jsCache</filter-name>
<filter-class>com.opcat.cache.CacheFilter</filter-class>
<init-param>
<param-name>private</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>expirationTime</param-name>
<!-- Change this to add the expiry time for re-validating the files -->
<param-value>0</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>jsCache</filter-name>
<url-pattern>*</url-pattern>
</filter-mapping>

Summary

Caching and Compression filters optimize HTTP request call, contents size and contents generation. Caching and Compression are most important task in terms of web application performance.  We can use attached project which is free and open source to use in your application.
 

Reference: Improve Performance by caching and compression from our JCG partner Nitin Kumar at the Tech My Talk blog.

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

JPA Mini Book

Learn how to leverage the power of JPA in order to create robust and flexible Java applications. With this Mini Book, you will get introduced to JPA and smoothly transition to more advanced concepts.

JVM Troubleshooting Guide

The Java virtual machine is really the foundation of any Java EE platform. Learn how to master it with this advanced guide!

Given email address is already subscribed, thank you!
Oops. Something went wrong. Please try again later.
Please provide a valid email address.
Thank you, your sign-up request was successful! Please check your e-mail inbox.
Please complete the CAPTCHA.
Please fill in the required fields.

One Response to "Improve Performance by caching and compression"

  1. Prasad says:

    couple of questions:

    how is servlet caching different from setting the HTTP cache headers? in the latter case the round trips can be avoided if the browser ends up serving the request from its own cache.

Leave a Reply


nine − 8 =



Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use | Privacy Policy | Contact
All trademarks and registered trademarks appearing on Java Code Geeks are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries.
Java Code Geeks is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.
Do you want to know how to develop your skillset and become a ...
Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

Get ready to Rock!
You can download the complementary eBooks using the links below:
Close