Site iconJava PDF Blog

How to enable GZIP Compression in Tomcat, Jetty, GlassFish and Payara

GZIP Compression is a widely supported method of reducing the file size of the content hosted by your Java Application Server. This reduces bandwidth usage and improves load times. We recommend enabling GZIP compression for .html, .css, .js, .svg, and .json files.

Follow the instructions below to enable GZIP compression of static assets hosted by Tomcat, Jetty, GlassFish or Payara.

Tomcat

  1. Open conf/server.xml
  2. Find <service name="Catalina">
  3. Find the <Connector /> tag inside it
  4. Add the following attributes to the Connector tag:
    • compression="on"
    • compressionMinSize="2048"
    • noCompressionUserAgents=""
    • compressableMimeType="text/html,text/css,text/plain,text/javascript,application/javascript,application/json,image/svg+xml"
  5. Restart the server and you’re done

Jetty

  1. Open etc/jetty.xml
  2. Find the <Configure id="Server" class="org.eclipse.jetty.server.Server"> tag
  3. Add in the following lines inside the Configure tag
      
      
          
              
                  
                  
                  
                  
                  
                    
                  
                      
                          
                      
                  
                    
                  
                  
              
          
      
    
  4. Restart the server and you’re done

GlassFish

  1. Open the GlassFish admin console (localhost:4848 for example)
  2. Go to the HTTP settings via: Configurations → server-config → Network Config → Network Listeners → http-listener-1/http-listener-2 (change the settings in both of these) → HTTP (tab at the top of the page)
  3. Edit the ‘Compression’ setting to be ‘on’
  4. Change the ‘Compressible Mime Types’ to use text/html,text/css,text/plain,text/javascript,application/javascript,application/json,image/svg+xml
  5. Click save and you’re done

Payara

  1. Open the Payara admin console (localhost:4848 for example)
  2. Go to the HTTP settings via: Configurations → server-config → Network Config → Network Listeners → http-listener-1/http-listener-2 (change the settings in both of these) → HTTP (tab at the top of the page)
  3. Edit the ‘Compression’ setting to be ‘on’
  4. Change the ‘Compressible Mime Types’ to use text/html,text/css,text/plain,text/javascript,application/javascript,application/json,image/svg+xml
  5. Click save and you’re done