Package com.isomorphic.servlet

# Class CompressionFilter

java.lang.Object
com.isomorphic.servlet.BaseFilter
com.isomorphic.servlet.CompressionFilter

All Implemented Interfaces:
  `jakarta.servlet.Filter`

public class CompressionFilter extends com.isomorphic.servlet.BaseFilter
This CompressionFilter is part of the optional Network Performance package. This filter enables highly configurable, cross-platform, dynamic compression of HTML and JavaScript code sent to the browser. This filter auto-detects compressable mime types and intelligently handles various edge cases such as servlet/JSP include()/forward() calls.

This filter requires isomorphic_compression.jar to be present in your WEB-INF/lib to work properly.

Please contact Isomorphic (http://forums.smartclient.com) to learn more about the Network Performance package.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `List`
  `compressableMimeTypes`
  Comma separated list of mime types that are compressable.
  `int`
  `compressThreshold`
  Minimum size of the dynamically captured buffer (in bytes) for compression to kick in.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `canCompressContext(RequestContext context)`
  Is a specific request context compressable? Default implementation will disallow compression for messaging requests (determined by looking at the target request path).

- ## Field Details

  - ### compressThreshold

    public int compressThreshold
    Minimum size of the dynamically captured buffer (in bytes) for compression to kick in. If the content-length is smaller then this size, it will be sent uncompressed.

    Default is 250 Bytes.

  - ### compressableMimeTypes

    public List compressableMimeTypes
    Comma separated list of mime types that are compressable.

    The CompressionFilter asks the container for the mimeType of the intercepted URL before bufferring. If the mimeType is known at that time and does not match this list of mimeTypes, the CompressionFilter avoids bufferring the response.

    If the mimeType is unknown, the CompressionFilter buffers the response in the hope that the upstream servlet/filter will set the mimeType. If the mimeType is still unknown or does not match this list of mimeTypes, the response will not be compressed.

    For optimal performance, you should ensure that the CompressionFilter only buffers responses that it can compress. You can do this by:

    - Registering the CompressionFilter for URLs that you know are compressable.
    - Making sure the container returns a mimeType for all/most file extensions used by your site (this is typically done in the server's web.xml file, and you can typically add/override server settings in your deployment web.xml.

    Note that if you wish to add extensions to the default list, you should test them against your target browser platforms to ensure that the compression will actually work for that mimeType.

    Also, make sure that what you specify here matches what your container returns as the mimeType for the extensions you intend to compress. For example, if your container is configured to return `text/javascript` for `*.js` files and you list only `text/ecmascript` here then compression will be disabled for `*.js` files.

    The comparison is a substring match of the specified mimeType against what the container/response returns. So, for example, if you specified `text/javascript` here and a JSP that was intercepted by the CompressionFilter set the mimeType via the `@page contentType` directive to text/javascript; charset=UTF-8, then the match would be successfull because the latter string contains the former. If you don't specify this parameter on the filter definition or specify it with an empty value, the CompressionFilter will use the following default: `text/html, text/xml, application/x-javascript, text/javascript, text/ecmascript, image/svg+xml, application/javascript`

- ## Method Details

  - ### canCompressContext

    public boolean canCompressContext(RequestContext context)
    Is a specific request context compressable? Default implementation will disallow compression for messaging requests (determined by looking at the target request path). May be overridden to disable compression for other request types (or if the messaging servlet mapping is changed).