Tag Archives: J2EE

GZIP content for mobile devices

One of the easiest, most obvious ways to lower the data transfer footprint of your mobile apps is to compress data. For some reason, I still see mobile web decks that output XHTML-MP in plain text instead of very-easy-to-implement GZIP compression. I’ve implemented GZIP output on multiple J2EE projects with the help of Jayson Falkner’s excellent GZIPFilter which is available in his article Two Servlet Filters Every Web Application Should Have.

To implement the filter in your own projects, download the three pieces of the filter: GZIPFilter, GZIPResponseStream, GZIPResponseWrapper and save them in your project. Then, in your web.xml add the following entries:


Compress
GZIPFilter


Compress
*.do

Remember to adjust the url-pattern to what’s appropriate for your webapp. I typically map my Spring MVC dispatcher servlet to *.do, but that’s just a hangover from Struts.

Once you’ve redeployed your webapp you should verify that output is rendering correctly in a desktop client such as Firefox.