How is compression (GZIP / DEFLATE) enabled; which content types should be compressed?
Short answer
It is enabled by checking Details → Compression on the HTTP vService. The Default Profile compresses only text/plain content with GZIP and Level 1; for text-based content such as HTML, CSS, JavaScript and JSON, a Compression profile is created on the Profiles → Compression screen and types such as text/html, text/css, application/javascript and application/json are added to the File Types list. Already compressed types such as JPEG, PNG, PDF, ZIP and video are not added to the list. Turning Compression on or off, or changing the Compression Level, restarts the vService.
Problem: Text Responses Travel Over the Network Larger Than Necessary
When HTML, CSS, JavaScript and JSON responses are compressed, their size drops noticeably; pages open faster on slow connections and bandwidth is saved. Compression is done while the response passes through TR7, without touching the application; if the client does not state its support with the Accept-Encoding header, the response is sent uncompressed (client compatibility check).
Solution: Three Methods
| Recommended types | Types not added |
|---|---|
text/html, text/css, text/plain, text/javascript, application/javascript, application/json, application/xml, text/xml, image/svg+xml | image/jpeg, image/png, image/gif, application/pdf, application/zip, video/*: they are already compressed; compressing them again only consumes processor time (types not included) |
| Your situation | Suitable method |
|---|---|
| Turning it on quickly (text/plain only) | Method 1: Default profile |
| Compressing web content such as HTML, CSS, JavaScript and JSON | Method 2: Custom Compression profile |
| From the command line | Method 3: WEB-CLI |
Method 1: Default Profile
- How it works When Compression is checked on the vService, the Default profile is applied: GZIP, Level 1,
text/plainonly. - Where it is openedLoad Balancer → Load Balancer vService List → Edit → Details → Compression
- Requirement Saving restarts the vService; it is done outside peak hours
- vService type HTTP
Step-by-Step Configuration
On the Load Balancer → Load Balancer vService List screen, the HTTP vService is selected and Edit is clicked.
In the Details panel, the Compression box is checked; Default profile comes selected (default profile behavior).
Save is clicked. Since the Default profile carries Level 1, saving restarts the vService and open connections are dropped (When does a change I make take effect; does it go live as soon as I save it?). In a cluster, it is also sent to the peer device with the default auto-sync; if Manual Sync Mode is on, it is sent with Synchronize.
Verification
An address that returns plain text is requested: curl -s -o /dev/null -D - -H "Accept-Encoding: gzip" https://www.example.com/robots.txt
Content-Encoding: gzipMethod 2: Custom Compression Profile Recommended
- How it works The content types in the File types list of the profile are compressed with the selected algorithm and level if the client supports it.
- Where it is openedLoad Balancer → Profiles → Compression → Add
- Requirement If Compression is being turned on for the first time on the vService or the level changes, saving restarts the vService
- vService type HTTP
Step-by-Step Configuration
Load Balancer → Profiles → Compression → Add is clicked (How to add). The profile can also be created from the vService form, with Add in the Compression row.
Name is entered; Compression Algorithm = GZIP (default; fewer clients support DEFLATE); Compression Level = Default or Level 1–9; a profile with Default selected is saved as Level 1 (What should the Compression Level be; what is its effect on CPU?).
One type per line is written in the File Types list: text/html, text/css, application/javascript, application/json, application/xml, text/plain. Types that are not in the suggestion list are typed manually; the type must be in the type/subtype format.
Add is clicked.
The vService is opened with Edit; Details → Compression is checked and the profile is selected from the list (How to add to a vService).
Save is clicked. If Compression is being turned on or off on this vService or the level of the profile is different from before, the vService is restarted and open connections are dropped; switching to a profile with the same level is applied without interruption. In a cluster, it is also sent to the peer device with the default auto-sync; if Manual Sync Mode is on, it is sent with Synchronize.
Verification
curl -s -o /dev/null -D - -H "Accept-Encoding: gzip" https://www.example.com/; the same request is also sent without Accept-Encoding.
Content-Encoding: gzip the first time · no header the second timeIn the Compression chart on the HTTP Frontend tab of the vService dashboard, Bytes Before Compression and Bytes After Compression are compared.
The After value is smaller than BeforeMethod 3: WEB-CLI
- How it works The profile is created with a WEB-CLI command and bound to the vService.
- Where it is opened TR7 WEB-CLI →
lb compression·lb service - Requirement WEB-CLI access; if
--compressionLevelis not written on the command line, the level is 1 (the Default option in the interface is also saved as Level 1) - vService type HTTP
Step-by-Step Configuration
The list field is written in the --fileTypes.0, --fileTypes.1… format, starting from zero:
lb compression add name web-sikistirma --algorithm gzip --compressionLevel 6 --fileTypes.0 text/html --fileTypes.1 text/css --fileTypes.2 application/javascript --fileTypes.3 application/json--compression takes the name of the profile; saving restarts the vService:
lb service update id <vService> --compression web-sikistirmaVerification
curl -s -o /dev/null -D - -H "Accept-Encoding: gzip" https://www.example.com/
Content-Encoding: gzipCommon Mistakes
- Assuming that checking Compression is enough. The Default profile compresses only
text/plain; for HTML, CSS and JavaScript, the types are added to a profile. - Adding compressed types. JPEG, PNG, GIF, PDF, ZIP and video do not get smaller when compressed again; they only consume processor time.
- Assuming that saving will not affect connections. When Compression is turned on or off or the level changes, the vService restarts; it is not done at peak hours.
- Overlooking the Modify response content action. If this action is on the same vService, responses are sent uncompressed (Can I modify the response body (e.g. inject a script into HTML, mask national ID / card numbers)?).
- Choosing the level at random. For the balance between level and processor load: What should the Compression Level be; what is its effect on CPU?
How it is done in the documentation
