Wednesday, January 27, 2010

Jetty 7 gzip Filter

Jetty includes a gzip-filter for dynamic compression of contents, thus saving bandwidth and enabling your site to load faster (especially important if you have a lot of javascript).

To configure it, add the follwing filter definition to your web.xml:


  <filter>
    <filter-name>GzipFilter</filter-name>
    <filter-class>org.eclipse.jetty.servlets.GzipFilter</filter-class>
    <init-param>
      <param-name>mimeTypes</param-name>
      <param-value>text/html,text/plain,text/xml,application/xhtml+xml,text/css,application/javascript,image/svg+xml</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>GzipFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping> 

Please note: This configuration is for Jetty 7. For Jetty 6 change the filter to org.mortbay.servlet.GzipFilter.

3 comments:

  1. Should this be at the root level (? Or within a servlet?

    Thanks!

    ReplyDelete
  2. This is set in the web.xml which you can find in the WEB-INF directory of your web application.

    ReplyDelete
  3. Hi,

    I do this, but only work if i compress the archive and put it togther (ie. myjs.js.gz). The server was not compress in gzip automatic.
    What i have to do?

    Thanks!

    ReplyDelete

Home

Followers