Compress API responses to cut bandwidth and latency using gzip, Brotli, and zstd, with curl verification and server configuration.
Agentic Workflow: Read -> Reason -> Act (compression)
You are Compression (api/general) — a sub-agent that Reads, Reasons, and Acts via allowed-tools.
1. Read — api context for compression
- Domain: Compress API responses to cut bandwidth and latency using gzip, Brotli, and zstd, with curl verification and server configuration.
- compression-verify: Verify compression headers and response size on API endpoints —
curl -s -H "Accept-Encoding: gzip" -D - -o /dev/null https://httpbin.org/get | g
- cli-tools: Compress and decompress payloads with gzip, brotli, and zstd —
gzip -9 -k response.json
- Check
knowledge and prerequisites: brotli, gunzip, gzip, zstd
2. Reason — think for compression
- For
compression-verify: Verify compression headers and response size on API endpoints — decide which checks to run
- For
cli-tools: Compress and decompress payloads with gzip, brotli, and zstd — decide which checks to run
- Evaluate trust/policy:
kdesk trust + kdesk doctor patterns for your inputs
3. Act — execute with compression tools
- Tools:
Glob, Grep, Read, Bash, Gzip (see frontmatter tools/allowed-tools)
- Use
safe_path for any write; record evidence (paths, checksums)
- Fingerprint:
compression:3dd985eb
Compression
Compress API responses to cut bandwidth and latency.
When to Use
- JSON-heavy APIs with large payloads
- Mobile clients on slow networks
- Reducing egress cost and p95 transfer time
Encode Selection
Prefer Brotli (br) for text-heavy JSON, then gzip, then zstd; always set Vary: Accept-Encoding.
Verify Endpoints
curl -s -H "Accept-Encoding: gzip" -D - -o /dev/null https://httpbin.org/get | grep -i content-encoding
curl -s -o /dev/null -w "compressed: %{size_download} bytes\n" -H "Accept-Encoding: gzip, br" https://httpbin.org/get
curl --compressed -s https://httpbin.org/get | wc -c
Compare with no encoding:
curl -s -o /dev/null -w "uncompressed: %{size_download} bytes\n" https://httpbin.org/get
CLI Tools
gzip -9 -k response.json
brotli -9 -o response.json.br response.json
zstd -19 -o response.json.zst response.json
Server Middleware (Express)
npm install compression
const compression = require('compression');
app.use(compression({ threshold: 1024 }));
Testing
curl -s -o /dev/null -w "gzip: %{size_download}\n" -H "Accept-Encoding: gzip" https://httpbin.org/get
curl -s -o /dev/null -w "br: %{size_download}\n" -H "Accept-Encoding: br" https://httpbin.org/get
Best Practices
- Compress above a small threshold (1KB) only
- Do not compress already-compressed media (images, video)
- Set Vary: Accept-Encoding on cached responses
- Never send both Content-Length and chunked encoding
- Use brotli when clients support it
- Keep compression CPU cost off the hot path with CDN caching
Capabilities
compression-verify
Verify compression headers and response size on API endpoints
Parameters:
url (string): Endpoint to check
accept_encoding (string): Accept-Encoding header value
Commands:
curl -s -H "Accept-Encoding: gzip" -D - -o /dev/null https://httpbin.org/get | grep -i content-encoding
curl -s -H "Accept-Encoding: gzip, br" -o /dev/null -w "%{size_download} bytes\n" https://httpbin.org/get
curl -s -o /dev/null -w "%{http_code}\n" -H "Accept-Encoding: gzip" https://httpbin.org/get
curl --compressed -s https://httpbin.org/get | wc -c
Examples:
cli-tools
Compress and decompress payloads with gzip, brotli, and zstd
Parameters:
file (string): File to compress
level (string): Compression level, e.g. 9 for gzip, 11 for brotli
Commands:
gzip -9 -k response.json
gunzip -k response.json.gz
brotli -9 -o response.json.br response.json
zstd -19 -o response.json.zst response.json
Examples:
- gzip -9 -k response.json && ls -la response.json.gz
- brotli -9 -o response.json.br response.json
- zstd -19 response.json -o response.json.zst
References
1---2name: "compression"3description: "Compress API responses to cut bandwidth and latency using gzip, Brotli, and zstd, with curl verification and server configuration. Use when working with compression verify, cli tools, api or when the user mentions compression verify, cli tools, api."4license: "MIT"5compatibility: "Requires brotli, gunzip, gzip, zstd. Needs network access."6metadata:7 source: https://skillmd.com/skills/opknock/compression8 author: Kdesk9 version: 2.0.010 category: api11allowed-tools: "Glob Grep Read Bash(brotli:*) Bash(curl:*) Bash(gunzip:*) Bash(gzip:*) Bash(zstd:*)"12---1314Compress API responses to cut bandwidth and latency using gzip, Brotli, and zstd, with curl verification and server configuration.1516## Agentic Workflow: Read -> Reason -> Act (compression)1718You are **Compression** (api/general) — a sub-agent that **Reads, Reasons, and Acts** via `allowed-tools`.1920### 1. Read — api context for `compression`21- Domain: Compress API responses to cut bandwidth and latency using gzip, Brotli, and zstd, with curl verification and server configuration.22- **compression-verify**: Verify compression headers and response size on API endpoints — `curl -s -H "Accept-Encoding: gzip" -D - -o /dev/null https://httpbin.org/get | g`23- **cli-tools**: Compress and decompress payloads with gzip, brotli, and zstd — `gzip -9 -k response.json`24- Check `knowledge` and `prerequisites: brotli, gunzip, gzip, zstd`2526### 2. Reason — think for `compression`27- For `compression-verify`: Verify compression headers and response size on API endpoints — decide which checks to run28- For `cli-tools`: Compress and decompress payloads with gzip, brotli, and zstd — decide which checks to run29- Evaluate trust/policy: `kdesk trust` + `kdesk doctor` patterns for your inputs3031### 3. Act — execute with `compression` tools32- Tools: `Glob`, `Grep`, `Read`, `Bash`, `Gzip` (see frontmatter `tools`/`allowed-tools`)33- Use `safe_path` for any write; record evidence (paths, checksums)34- Fingerprint: `compression:3dd985eb`3536# Compression3738Compress API responses to cut bandwidth and latency.3940## When to Use4142- JSON-heavy APIs with large payloads43- Mobile clients on slow networks44- Reducing egress cost and p95 transfer time4546## Encode Selection4748Prefer Brotli (br) for text-heavy JSON, then gzip, then zstd; always set Vary: Accept-Encoding.4950## Verify Endpoints5152```bash53curl -s -H "Accept-Encoding: gzip" -D - -o /dev/null https://httpbin.org/get | grep -i content-encoding54curl -s -o /dev/null -w "compressed: %{size_download} bytes\n" -H "Accept-Encoding: gzip, br" https://httpbin.org/get55curl --compressed -s https://httpbin.org/get | wc -c56```5758Compare with no encoding:5960```bash61curl -s -o /dev/null -w "uncompressed: %{size_download} bytes\n" https://httpbin.org/get62```6364## CLI Tools6566```bash67gzip -9 -k response.json68brotli -9 -o response.json.br response.json69zstd -19 -o response.json.zst response.json70```7172## Server Middleware (Express)7374```bash75npm install compression76```7778```js79const compression = require('compression');80app.use(compression({ threshold: 1024 }));81```8283## Testing8485```bash86curl -s -o /dev/null -w "gzip: %{size_download}\n" -H "Accept-Encoding: gzip" https://httpbin.org/get87curl -s -o /dev/null -w "br: %{size_download}\n" -H "Accept-Encoding: br" https://httpbin.org/get88```8990## Best Practices9192- Compress above a small threshold (1KB) only93- Do not compress already-compressed media (images, video)94- Set Vary: Accept-Encoding on cached responses95- Never send both Content-Length and chunked encoding96- Use brotli when clients support it97- Keep compression CPU cost off the hot path with CDN caching9899## Capabilities100101### compression-verify102Verify compression headers and response size on API endpoints103104**Parameters:**105- `url` (string): Endpoint to check106- `accept_encoding` (string): Accept-Encoding header value107108**Commands:**109- `curl -s -H "Accept-Encoding: gzip" -D - -o /dev/null https://httpbin.org/get | grep -i content-encoding`110- `curl -s -H "Accept-Encoding: gzip, br" -o /dev/null -w "%{size_download} bytes\n" https://httpbin.org/get`111- `curl -s -o /dev/null -w "%{http_code}\n" -H "Accept-Encoding: gzip" https://httpbin.org/get`112- `curl --compressed -s https://httpbin.org/get | wc -c`113114**Examples:**115- curl -s -H "Accept-Encoding: gzip, br" -D - -o /dev/null https://httpbin.org/get | grep -i 'content-encoding'116- curl -s -o /dev/null -w "%{size_download}\n" -H "Accept-Encoding: gzip" https://httpbin.org/get117- curl -s -o /dev/null -w "%{size_download}\n" -H "Accept-Encoding: gzip, br, zstd" https://httpbin.org/get118119### cli-tools120Compress and decompress payloads with gzip, brotli, and zstd121122**Parameters:**123- `file` (string): File to compress124- `level` (string): Compression level, e.g. 9 for gzip, 11 for brotli125126**Commands:**127- `gzip -9 -k response.json`128- `gunzip -k response.json.gz`129- `brotli -9 -o response.json.br response.json`130- `zstd -19 -o response.json.zst response.json`131132**Examples:**133- gzip -9 -k response.json && ls -la response.json.gz134- brotli -9 -o response.json.br response.json135- zstd -19 response.json -o response.json.zst136137## References138- [MDN Content-Encoding](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Encoding)139- [Brotli GitHub](https://github.com/google/brotli)