Skip to content

fix(server): add zstd HTTP compression with gzip fallback#27935

Open
BYK wants to merge 1 commit into
anomalyco:devfrom
BYK:fix/zstd-compression
Open

fix(server): add zstd HTTP compression with gzip fallback#27935
BYK wants to merge 1 commit into
anomalyco:devfrom
BYK:fix/zstd-compression

Conversation

@BYK
Copy link
Copy Markdown
Contributor

@BYK BYK commented May 16, 2026

Issue for this PR

Closes #27932

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Adds zstd as the preferred compression encoding in the HTTP compression middleware, falling back to gzip and deflate. Modern browsers (Chrome 123+, Firefox 126+, Safari 18+) automatically send zstd in Accept-Encoding.

Zstd provides ~30-40% better compression than gzip at similar CPU cost. Uses Bun.zstdCompressSync() which is available natively in Bun.

Changes:

  • Add "zstd" to the Encoding type union
  • Check for zstd before gzip in pickEncoding to prefer it
  • Add Bun.zstdCompressSync() call for zstd encoding

All existing guards (SSE exclusion, threshold, no-transform, etc.) apply to zstd as well.

How did you verify your code works?

Tested locally by sending requests with Accept-Encoding: zstd, gzip and verifying the response uses Content-Encoding: zstd. Verified fallback to gzip when zstd is not in Accept-Encoding.

Screenshots / recordings

N/A — network-level improvement.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Add zstd as the preferred compression encoding, falling back to gzip
and deflate. Modern browsers (Chrome 123+, Firefox 126+, Safari 18+)
automatically send zstd in Accept-Encoding. Zstd provides ~30-40%
better compression than gzip at similar speeds.

Uses Bun.zstdCompressSync which is available natively in Bun.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HTTP compression middleware only supports gzip/deflate, missing zstd

1 participant