9

I have a Jetty server which does not have compression enabled (I tested this here). How can I enable compression?

Caleb
  • 11,583
  • 4
  • 35
  • 49
yazz.com
  • 6,743
  • 14
  • 37
  • 38

2 Answers2

11

You have to enable the GzipFilter to make Jetty return compressed content. Have a look here on how to do that: http://blog.max.berger.name/2010/01/jetty-7-gzip-filter.html

You can also use the gzip init parameter to make Jetty search for compressed content. That means if the file file.txt is requested, Jetty will watch for a file named file.txt.gz and returns that.

fab
  • 2,308
  • 2
  • 16
  • 14
0

In Jetty 8 (?) and later, you will have to use a GzipHandler as GzipFilter seems to be deprecated/missing:

<Configure class="org.eclipse.jetty.webapp.WebAppContext">
    <Set name="handler">
        <New class="org.eclipse.jetty.server.handler.GzipHandler"/>
        <!-- package name might have changed in Jetty 9; possibly org.eclipse.jetty.server.handler.gzip.GzipHandler
             as per https://stackoverflow.com/questions/35725538/jetty-gziphandler-configuration -->
    </Set>
</Configure>

The gzip init parameter still works, in case you want to only serve static content (which would in fact be more efficient than going through the GZip handler). However it is advisable to retain the uncompressed copies on the server as well, as Jetty may need to serve uncompressed content for incompatible browsers (mostly IE).

  • The XML configuration could be added to `WEB-INF/jetty-env.xml` of the webapp (there are other options as well, `jetty-web.xml`, `web-jetty.xml`, `classes/org/eclipse/jetty/webapp/webdefault.xml`,...) – Janaka Bandara Dec 21 '17 at 02:23