Jetty provides Gzip Filter to enable dynamic compression of contents like html, javascript, css etc. Just a servlet filter 'org.eclipse.jetty.servlets.GzipFilter' needs to be configured in web.xml to save bandwidth and speed up your website.

Tools and Technologies used in this article

  1. Jetty 8
  2. Java Web Application

Note: Prior to Jetty 7, all versions were hosted in, so refer that site to get the correct package name of GzipFilter class. For example, In Jetty 6 we need to use org.mortbay.servlet.GzipFilter.

Update web.xml

Add GzipFilter in the 'web.xml' file of your web application to be deployed in Jetty server.

File: web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="" xmlns:xsi="" xsi:schemaLocation="" metadata-complete="false">

Use comma separated mimeTypes for which you want Jetty to apply GZIP compression.

Note: Don't use gzip compression for image (except SVG), video, PDF or other binary files. These are already compressed, so you will not get any additional benefit out of it. .

Download SrcCodes

All code samples shown in this post are available in the following link web.xml