diff --git a/src/v3/features/cache-control-headers.md b/src/v3/features/cache-control-headers.md index 3f72a93..e0cf6e7 100644 --- a/src/v3/features/cache-control-headers.md +++ b/src/v3/features/cache-control-headers.md @@ -40,6 +40,12 @@ A `max-age` of _one year_ is applied only to the following file types. avif, bmp, bz2, css, doc, gif, gz, htc, ico, jpeg, jpg, js, jxl, map, mjs, mp3, mp4, ogg, ogv, pdf, png, rar, rtf, tar, tgz, wav, weba, webm, webp, woff, woff2, zip ``` +> [!INFO] Error responses +> +> The file type `max-age` values apply only to successful (`2xx`) and `304 Not Modified` responses. Other file responses, such as a `404 Not Found` for a missing `/app.css`, get the `no-cache` directive. +> +> With a [fallback page](error-pages.md#fallback-page-for-use-with-client-routers) configured, a `GET` for a missing file is answered with `200 OK` and the fallback page, so it still gets the file type `max-age` value. + Below is an example of how to enable the feature. ```sh diff --git a/src/v3/features/custom-http-headers.md b/src/v3/features/custom-http-headers.md index 973a1ad..b55f40e 100644 --- a/src/v3/features/custom-http-headers.md +++ b/src/v3/features/custom-http-headers.md @@ -10,12 +10,13 @@ outline: deep The Server HTTP response headers should be defined mainly as an [Array of Tables](https://toml.io/en/v1.0.0#array-of-tables). -Each table entry should have two key/value pairs: +Each table entry should have the following key/value pairs: - One `source` key containing a string _glob pattern_. - One `headers` key containing a [set or hash table](https://toml.io/en/v1.0.0#table) describing plain HTTP headers to apply. +- An optional `status` key containing an array of HTTP response status codes. -A particular set of HTTP headers can only be applied when a `source` matches against the request URI. +A particular set of HTTP headers can only be applied when a `source` matches against the request URI and, if `status` is defined, the response status code is one of its values. > [!INFO] Custom HTTP headers take precedence over existing ones > @@ -33,9 +34,21 @@ The source is a [Glob pattern]( [!INFO] Fallback page +> +> With a [fallback page](error-pages.md#fallback-page-for-use-with-client-routers) configured, a `GET` for a missing file is answered with `200 OK` and the fallback page, so status filtering does not exclude it. + +Entries apply in order and a later entry replaces a header set by an earlier one. Below, every `/assets/**` response gets `no-cache`, and the second entry replaces it with `immutable` for `200`, `206` and `304` responses only. + +```toml +[advanced] + +[[advanced.headers]] +source = "/assets/**" +headers = { Cache-Control = "no-cache" } + +[[advanced.headers]] +source = "/assets/**" +status = [200, 206, 304] +headers = { Cache-Control = "public, max-age=31536000, immutable" } +```