docs: encode short syntax (#445)

This commit is contained in:
Kévin Dunglas 2025-01-09 17:49:50 +01:00 committed by GitHub
parent ef31c7646a
commit ff1088fd1f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 16 additions and 10 deletions

View file

@ -134,7 +134,7 @@ It's good practice to compress responses with a quick and modern compression alg
```caddy
localhost
encode zstd gzip
encode
templates
file_server browse
```
@ -156,7 +156,7 @@ Our Caddyfile so far:
```caddy
localhost
encode zstd gzip
encode
templates
file_server browse
```
@ -165,7 +165,7 @@ is equivalent to this one:
```caddy
localhost {
encode zstd gzip
encode
templates
file_server browse
}

View file

@ -11,7 +11,7 @@ It looks like this:
```caddy
example.com {
root * /var/www/wordpress
encode gzip
encode
php_fastcgi unix//run/php/php-version-fpm.sock
file_server
}

View file

@ -22,7 +22,7 @@ Encodes responses using the configured encoding(s). A typical use for encoding i
## Syntax
```caddy-d
encode [<matcher>] <formats...> {
encode [<matcher>] [<formats...>] {
# encoding formats
gzip [<level>]
zstd [<level>]
@ -36,7 +36,7 @@ encode [<matcher>] <formats...> {
}
```
- **&lt;formats...&gt;** is the list of encoding formats to enable. If multiple encodings are enabled, the encoding is chosen based the request's Accept-Encoding header; if the client has no strong preference (q-factor), then the first supported encoding is used.
- **&lt;formats...&gt;** is the list of encoding formats to enable. If multiple encodings are enabled, the encoding is chosen based the request's Accept-Encoding header; if the client has no strong preference (q-factor), then the first supported encoding is used. If omitted, `zstd` (preferred) and `gzip` are enabled by default.
- **gzip** <span id="gzip"/> enables Gzip compression, optionally at a specified level.
@ -99,12 +99,18 @@ Enable Zstandard and Gzip compression (with Zstandard implicitly preferred, sinc
encode zstd gzip
```
As this is the default value, the previous configuration is strictly equivalent to:
```caddy-d
encode
```
And in a full site, compressing static files served by [`file_server`](file_server):
```caddy
example.com {
root * /srv
encode zstd gzip
encode
file_server
}
```

View file

@ -66,7 +66,7 @@ With a PHP FastCGI service running, something like this works for most modern PH
```caddy
example.com {
root * /srv/public
encode gzip
encode
php_fastcgi localhost:9000
file_server
}
@ -217,7 +217,7 @@ A typical SPA config usually looks something like this:
```caddy
example.com {
root * /srv
encode gzip
encode
try_files {path} /index.html
file_server
}
@ -227,7 +227,7 @@ If your SPA is coupled with an API or other server-side-only endpoints, you will
```caddy
example.com {
encode gzip
encode
handle /api/* {
reverse_proxy backend:8000