From 13367a80ce4234ccc68b0ac619f64ed3e7ef6bc3 Mon Sep 17 00:00:00 2001 From: Fabian Date: Fri, 11 Oct 2024 16:19:29 +0200 Subject: [PATCH] Add Cache-Control "public,max-age=0,must-revalidate" to index.html in SPA Example (#410) Co-authored-by: Francis Lavoie --- src/docs/markdown/caddyfile/patterns.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/docs/markdown/caddyfile/patterns.md b/src/docs/markdown/caddyfile/patterns.md index adcba9c..0e858ee 100644 --- a/src/docs/markdown/caddyfile/patterns.md +++ b/src/docs/markdown/caddyfile/patterns.md @@ -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