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.
GZIP compression on Tomcat
- Open
conf/server.xml
- Find
<service name="Catalina">
- Find the
<Connector />
tag inside it - 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"
- Restart the server and you’re done
GZIP compression on Jetty
- Open
etc/jetty.xml
- Find the
<Configure id="Server" class="org.eclipse.jetty.server.Server">
tag - Add in the following lines inside the Configure tag
<Call name="insertHandler"> <Arg> <New id="GzipHandler" class="org.eclipse.jetty.server.handler.gzip.GzipHandler"> <Set name="minGzipSize"><Property name="jetty.gzip.minGzipSize" deprecated="gzip.minGzipSize" default="2048"/></Set> <Set name="checkGzExists"><Property name="jetty.gzip.checkGzExists" deprecated="gzip.checkGzExists" default="false"/></Set> <Set name="compressionLevel"><Property name="jetty.gzip.compressionLevel" deprecated="gzip.compressionLevel" default="-1"/></Set> <Set name="inflateBufferSize"><Property name="jetty.gzip.inflateBufferSize" default="0"/></Set> <Set name="syncFlush"><Property name="jetty.gzip.syncFlush" default="false" /></Set> <Set name="excludedAgentPatterns"> <Array type="String"> <Item><Property name="jetty.gzip.excludedUserAgent" deprecated="gzip.excludedUserAgent" default=".*MSIE.6.0.*"/></Item> </Array> </Set> <Set name="includedMethodList"><Property name="jetty.gzip.includedMethodList" default="GET" /></Set> <Set name="excludedMethodList"><Property name="jetty.gzip.excludedMethodList" default="" /></Set> </New> </Arg> </Call>
- Restart the server and you’re done
GZIP compression on GlassFish
- Open the GlassFish admin console (
localhost:4848
for example) - 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)
- Edit the ‘Compression’ setting to be ‘on’
- Change the ‘Compressible Mime Types’ to use
text/html,text/css,text/plain,text/javascript,application/javascript,application/json,image/svg+xml
- Click save and you’re done
GZIP compression on Payara
- Open the Payara admin console (
localhost:4848
for example) - 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)
- Edit the ‘Compression’ setting to be ‘on’
- Change the ‘Compressible Mime Types’ to use
text/html,text/css,text/plain,text/javascript,application/javascript,application/json,image/svg+xml
- Click save and you’re done
You can read our other article to know how to enable GZIP compression on Apache and NGINX. You can also read this article learn more about GZIP compression and its advantages.
Our software libraries allow you to
Convert PDF files to HTML |
Use PDF Forms in a web browser |
Convert PDF Documents to an image |
Work with PDF Documents in Java |
Read and write HEIC and other Image formats in Java |