Zstd not working?! (caddy always prefers gzip)

1. Output of caddy version:

v2.5.2 h1:eCJdLyEyAGzuQTa5Mh3gETnYWDClo1LjtQm2q9RNZrs=

2. How I run Caddy:

systemd

a. System environment:

Distributor ID: Ubuntu
Description: Ubuntu 22.04 LTS
Release: 22.04
Codename: jammy

systemd 249 (249.11-0ubuntu3.4)
+PAM +AUDIT +SELINUX +APPARMOR +IMA +SMACK +SECCOMP +GCRYPT +GNUTLS +OPENSSL +ACL +BLKID +CURL +ELFUTILS +FIDO2 +IDN2 -IDN +IPTC +KMOD +LIBCRYPTSETUP -LIBFDISK +PCRE2 -PWQUALITY -P11KIT -QRENCODE +BZIP2 +LZ4 +XZ +ZLIB +ZSTD -XKBCOMMON +UTMP +SYSVINIT default-hierarchy=unified

b. Command:

systemd

c. Service/unit/compose file:

[Unit]
Description=Caddy
Documentation=https://caddyserver.com/docs/
After=network.target network-online.target
Requires=network-online.target

[Service]
Type=notify
User=caddy
Group=caddy
ExecStart=/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile
ExecReload=/usr/bin/caddy reload --config /etc/caddy/Caddyfile --force
TimeoutStopSec=5s
LimitNOFILE=1048576
LimitNPROC=512
PrivateTmp=true
ProtectSystem=full
AmbientCapabilities=CAP_NET_BIND_SERVICE

[Install]
WantedBy=multi-user.target

d. My complete Caddy config:

Caddyfile:

import /etc/caddy/snippets/global.conf
import /etc/caddy/sites/*.conf

snippets/global.conf

(encoding) {
    encode zstd gzip
}

sites/example.conf

example.com {
    root * /var/www/example.com/httpdocs

    # IMPORT DEFAULTS
    import encoding
   
    # ...
}

3. The problem I’m having:

Caddy uses always gzip instead of zstd, no matter what I try. My network analysis shows content-encoding: gzip. Is there a possibility that I need to install zstd on the OS? E.g. apt install zstd (if yes, then this should be mentioned in the caddy docs) or is zstd directly integrated in the compiled caddy application? There seems to be no additional output / logs to warn the user about this behavior.

4. Error messages and/or full log output:

No errors.

5. What I already tried:

I’ve placed “encode zlib gzip” directly in the sites configuration. But there is no difference, caddy always uses gzip no matter what I do or try.

Almost no clients support Zstandard. :frowning:

Thank you! I didn’t know this, this saves me the headache of searching further and wasting time :smiley: It’s really strange all the tutorials I read didn’t mention this.

1 Like

To clarify, it’s not a problem with Caddy or what you have installed. Caddy uses a pure-Go implementation of zstd, so it’s bundled with Caddy. We use GitHub - klauspost/compress: Optimized Go Compression Packages for our compression needs.

But yeah, most browsers don’t have zstd support. Chrome and Firefox support gzip, deflate, br – that’s what they send in the Accept-Encoding header.

Gzip and Deflate are very similar – same underlying compression algorithm, but they differ in their header/footer info and the checksum algorithm used. See asp.net - What is the advantage of GZIP vs DEFLATE compression? - Stack Overflow

Caddy doesn’t support Brotli out of the box because there’s no fast pure-Go implementation yet. Brotli is pretty slow at compressing, but produces smaller results with still-very-good decompression performance. So it’s a good option when pre-compressing files, and Caddy’s file_server can serve these pre-compressed files for you if you need. But that’s a more advanced usecase and depends on your site’s build tooling to support it.

1 Like

This topic was automatically closed after 30 days. New replies are no longer allowed.