Created
December 14, 2024 16:53
-
-
Save monochromer/135afb8bc7289ffecba50f457258a519 to your computer and use it in GitHub Desktop.
Caddy server autoserving `avif` and `webp` images. For example, instead of `image.png` serve `image.png.avif` if browser support it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://localhost:8443 { | |
tls internal | |
vars { | |
staticFolder "./public" | |
} | |
map {header.Accept} {avifSuffix} { | |
~image/avif avif | |
default '' | |
} | |
map {header.Accept} {webpSuffix} { | |
~image/webp webp | |
default '' | |
} | |
@static { | |
path *.css *.js *.gif *.jpg *.jpeg *.png *.avif *.webp *.svg *.woff2 *.woff | |
} | |
header @static Cache-Control "public, immutable, max-age=5184000" | |
@images-to-rewrite { | |
path_regexp \.(jpg|jpeg|png|gif)$ | |
} | |
handle @images-to-rewrite { | |
header { | |
Vary Accept | |
} | |
root {vars.staticFolder} | |
try_files {path}.{avifSuffix} {path}.{webpSuffix} {path} =404 | |
} | |
file_server { | |
root {vars.staticFolder} | |
precompressed br gzip zstd | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment