Just a tip to reduce lines a bit:
file {
try_files {path}.br
}
file {path}.br
And also:
@cacheFavicon {
path_regexp favicon\.
}
@cacheFavicon path_regexp favicon\.
This one’s a bit more fun — you might be able to make use of import args to parameterize all of this to reduce the amount of lines:
Maybe something like this:
(precompressed) {
@{args.0}{args.1} {
header Accept-Encoding *{args.2}*
path *.{args.0}
file {path}.{args.1}
}
handle @{args.0}{args.1} {
rewrite {path}.{args.1}
header Content-Encoding {args.2}
header Content-Type {args.3}
header Cache-Control max-age={args.4},public
}
}
...
import precompressed html br br text/html 300
import precompressed html gz gzip text/html 300
import precompressed js br br application/javascript 2628000
import precompressed js gz gzip application/javascript 2628000
import precompressed map br br application/json 2628000
import precompressed map gz gzip application/json 2628000
import precompressed css br br "text/css; charset=utf-8" 2628000
import precompressed css gz gzip "text/css; charset=utf-8" 2628000
Give this a shot, I didn’t test to confirm this will do exactly the right thing. But I hope so!
You can use the caddy adapt
command to get the JSON representation of the Caddyfile to make sure that it ends up looking about the same as your long version.