Monday, October 16, 2017

Enabling HTTP Compression in GlassFish / Payara

Enable HTTP compression on GlassFish / Payara servers to reduce response time and make web applications faster.

Edit GLASSFISH_HOME//glassfish/domains/domain1/config/domain.xml

<network-config>
  <protocols>
    <protocol name="http-listener-1">
      <http max-connections="250" default-virtual-server="server"
            compression="on" 
            compression-min-size-bytes="128"
            compressable-mime-type="text/html,text/css,text/plain,text/xml,application/javascript,application/json">
        <file-cache></file-cache>
      </http>
      <ssl></ssl>
    </protocol>
    <protocol name="http-listener-2" security-enabled="true">
      <http max-connections="250" default-virtual-server="server"
            compression="on" 
            compression-min-size-bytes="128"
            compressable-mime-type="text/html,text/css,text/plain,text/xml,application/javascript,application/json">
        <file-cache></file-cache>
      </http>
      <ssl classname="com.sun.enterprise.security.ssl.GlassfishSSLImpl" cert-nickname="s1as"></ssl>
    </protocol>

Example with a reduction from 136 KB down to 23 KB (5.9x), considerabily reducing the network traffic.

Before (without HTTP compression)

After (with HTTP compression)