What is GZip

GZip is a cross-platform product written in C Programming language for the purpose of data compression. It was developed by Jean Loup and Mark Adler as compression tool for UNIX operating system. It is distributed with a GNU public license. You can find more information about the history and working of GZip on the wikipedia page for GZip

gzip is the process of compressing of content by server before sending to the web browser. The web browser then decompress the content and renders the page. The advantage of having gzip is reduced website load time and good user experience.

Tip: If you are using Firebug addon in Firefox then you can analyze the request and response to see if gzip is being used for a particular URL. Here is a screenshot which shows if gzip is being used in a server request.

gzip headers

GZip vs DEFLATE

Note that gzip is not exactly same as DEFLATE as gzip involves extra processing for computing check-sum and addition of header and footer. This extra processing is required as it acts as signature. Not all servers support DEFLATE out of the box but almost all servers (Tomcat, JBoss, WAMP, IIS, WebSphere and Weblogic etc.) support gzip compression. You may need to enable gzip by going to the configuration settings of server.

Here I will show how to enable gzip on famous servers viz. Tomcat and WAMP. While Tomcat is used for Java web applications, WAMP for PHP applications.

How to configure gzip on Tomcat

1) Go to $TOMCAT_HOME/conf and edit server.xml

2) Edit the HTTP connector as shown in the following code snippet:

Replace

    <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />

with

 <Connector port="8080" protocol="HTTP/1.1" 
               connectionTimeout="20000" 
               redirectPort="8443" 
               compression = "on"
               compressableMimeType="text/html,text/xml,text/plain"
               compressionMinSize="2048"/>

You may want to change the value of compression attribute in above code from on to force to ensure that gzip content is always served. The value on causes only text data to be compressed.

3) Restart tomcat and check HTTP headers for web application.

How to configure gzip on WAMP

1) Enable “headers_module” and “deflate_module” from WAMP tray configuration as shown below:

2) Open httpd.conf file and add the following code at the end of file:

<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/x-javascript application/javascript
</ifmodule>

3) Restart WAMP server

Related Posts

Enable gzip in Tomcat and WAMP admin Java EE
What is GZip GZip is a cross-platform product written in C Programming language for the purpose of data compression. It was developed by Jean Loup and Mark Adler as compression tool for UNIX operating system. It is distributed with a GNU public license. You can find more information about...
<h2>What is GZip</h2> GZip is a cross-platform product written in C Programming language for the purpose of data compression. It was developed by Jean Loup and Mark Adler as compression tool for UNIX operating system. It is distributed with a GNU public license. You can find more information about the history and working of GZip on the <a href="http://en.wikipedia.org/wiki/Gzip">wikipedia page for GZip</a> gzip is the process of compressing of content by server before sending to the web browser. The web browser then decompress the content and renders the page. The advantage of having gzip is reduced website load time and good user experience. Tip: If you are using Firebug addon in Firefox then you can analyze the request and response to see if gzip is being used for a particular URL. Here is a screenshot which shows if gzip is being used in a server request. <img src="http://www.javaexperience.com/wp-content/uploads/2012/11/gzip-headers.png" alt="gzip headers" width="622" height="390" class="alignnone size-full wp-image-3523" /> <h2>GZip vs DEFLATE</h2> Note that gzip is not exactly same as DEFLATE as gzip involves extra processing for computing check-sum and addition of header and footer. This extra processing is required as it acts as signature. Not all servers support DEFLATE out of the box but almost all servers (Tomcat, JBoss, WAMP, IIS, WebSphere and Weblogic etc.) support gzip compression. You may need to enable gzip by going to the configuration settings of server. Here I will show how to enable gzip on famous servers viz. Tomcat and WAMP. While Tomcat is used for Java web applications, WAMP for PHP applications. <h2>How to configure gzip on Tomcat</h2> 1) Go to $TOMCAT_HOME/conf and edit server.xml 2) Edit the HTTP connector as shown in the following code snippet: Replace 1 with 1 You may want to change the value of compression attribute in above code from on to force to ensure that gzip content is always served. The value on causes only text data to be compressed. 3) Restart tomcat and check HTTP headers for web application. <h2>How to configure gzip on WAMP</h2> 1) Enable "headers_module" and "deflate_module" from WAMP tray configuration as shown below: <img class="alignnone size-full" src="http://www.javaexperience.com/wp-content/uploads/2012/11/WAMP-gzip-compression.png" width="339" height="743"/> 2) Open httpd.conf file and add the following code at the end of file: 1 3) Restart WAMP server
What are the various JSP Implicit Objects
Adding JSP Comments
The following two tabs change content below.
I run this blog with lots of passion. In this website, you will find tutorials on Core Java, Spring, Struts, Web Applications, Portals and Database. Please support me and the website by sharing the posts on your facebook / twitter. You can tap the share button at the top of each post. Thanks for the support.

Comments

comments