Fork me on GitHub
Edit on GitHub << back to Tag Reference

compress

Please make sure you have read the Tag Syntax document and understand how tag attribute syntax works.

Description

Compresses HTML output by removing unnecessary whitespace between tags while preserving content within tags. This helps reduce the size of generated HTML output, improving page load times and bandwidth usage.

The compress tag can be controlled globally via the struts.tag.compress.enabled configuration property and is automatically disabled in development mode for easier debugging.

Compress wrapped content

Security: The compress tag includes built-in protections against DoS attacks and sensitive data exposure. Large content exceeding the configured maximum size (default 10MB) will be skipped without compression. Log messages are automatically truncated to prevent sensitive data from appearing in logs.

Attributes

Dynamic Attributes Allowed:

false

Name

Required

Default

Evaluated

Type

Description

force false false String Force output compression
performClearTagStateForTagPoolingServers false false false Boolean Whether to clear all tag state during doEndTag() processing (if applicable)

Security Features

Examples

Basic usage:

<s:compress>
    <div>
        <p>This HTML will be compressed</p>
        <span>Whitespace between tags will be removed</span>
    </div>
</s:compress>

Force compression in development mode:

<s:compress force="true">
    <div>
        <p>This will be compressed even in devMode</p>
    </div>
</s:compress>

Configuration:

Control compression globally in struts.xml:


<constant name="struts.tag.compress.enabled" value="true"/>
<constant name="struts.tag.compress.maxSize" value="10485760"/>

Or in struts.properties:

struts.tag.compress.enabled=true
struts.tag.compress.maxSize=10485760

Since

Available since Struts 7.2.0

Follow @x