1. Caddy version (caddy version
):
v2.0.0
2. How I run Caddy:
I am trying to put together configuration for Caddy that caches assets like JS and CSS for a long time but causes the HTML pages to always re-validate. The following configuration is doing the trick currently, with the @html
matcher using path matching to match index pages, but I’m wondering if there is a better way to achieve this.
file_server {
root "{$DATA}/www"
}
@assets {
path "*.js"
path "*.css"
}
header @assets {
Cache-Control "max-age=31536000"
}
@html {
path */
not path /api*
}
header @html {
Cache-Control "must-revalidate"
}
a. System environment:
Caddy binary on macOS
b. Command:
caddy run --config Caddyfile
c. Service/unit/compose file:
N/A
d. My complete Caddyfile or JSON config:
Can provide more detail if needed
3. The problem I’m having:
I’m wondering if there is a better way to implement the match for HTML pages.
My thinking has been that I’d like to do this by looking at a matcher on the response Content-Type
header for text/html*
that I can then modify things for, after the file_server
module has picked the file and served it.
5. What I already tried:
- Specifying
header Content-Type text/html*
in the @html matcher, but this is just for the request headers and doesn’t work - Specifying
path *.html
in the @html matcher, in the hope that paths were internally re-written to be the full index.html page, but this doesn’t work
6. Links to relevant resources:
- header directive: header (Caddyfile directive) — Caddy Documentation
- matchers: Request matchers (Caddyfile) — Caddy Documentation
- various other posts on this forum about caching which don’t seem to touch the file_server index pages specifically