Add Cache-Control "public,max-age=0,must-revalidate" to index.html in SPA Example (#410)

Co-authored-by: Francis Lavoie <lavofr@gmail.com>
This commit is contained in:
Fabian 2024-10-11 16:19:29 +02:00 committed by GitHub
parent 4a71f732b2
commit 13367a80ce
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -241,6 +241,15 @@ example.com {
}
```
If your `index.html` is static, you may want to consider adding a `Cache-Control` header to instruct clients to cache it. Since the `try_files` rewrite is used to serve it from other paths, you can wrap the `try_files` with a `route` so that the `header` handler runs after the rewrite (it normally would run before due to the [directive order](/docs/caddyfile/directives#directive-order)):
```caddy-d
route {
try_files {path} /index.html
header /index.html Cache-Control "public, max-age=0, must-revalidate"
}
```
## Caddy proxying to another Caddy