Skip to content

Commit 3835532

Browse files
Update Static Caching Docs for Headers CLI argument (#1674)
Co-authored-by: Duncan McClean <duncan@duncanmcclean.com>
1 parent bdb8610 commit 3835532

1 file changed

Lines changed: 42 additions & 1 deletion

File tree

content/collections/docs/static-caching.md

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,12 @@ The `static:warm` command supports various arguments:
244244
For example with `--max-depth=1` it will visit pages like `/about` and `/products` but not `/products/cool-new-shoes-1` or `/any/other/path/that/is/too/deep`.
245245
* **`--max-requests`**
246246
Limits the number of requests made by the command. Likely makes the most sense to be used alongside the `--uncached` option.
247+
* **`--header`**
248+
Allows you to specify custom HTTP headers to be sent with each request. Can be used multiple times to set multiple headers. Useful for APIs, protected routes, or any scenario where custom headers are required.
249+
250+
For example: `--header="Authorization: Bearer your_token" --header="X-Ignore-Cache: true"`
251+
252+
You can find [practical examples](#custom-headers) of this parameter below.
247253

248254
Depending on your site's setup, it might be a good idea to add this command to your deployment script.
249255

@@ -327,6 +333,41 @@ class AppServiceProvider
327333
}
328334
```
329335

336+
### Custom headers
337+
338+
The `--headers` option can be used in advanced scenarios to control how the static cache is warmed. Here are some practical examples:
339+
340+
#### Bypassing cache for refreshes with Nginx
341+
342+
If you have custom Nginx rules, you can check for a specific header (e.g., `X-Cache-Refresh: 1`) and bypass the `try_files` static cache, forcing a fresh request to the backend. For example:
343+
344+
```nginx
345+
location / {
346+
if ($http_x_cache_refresh = "1") {
347+
proxy_pass http://127.0.0.1:8000; # your statamic server
348+
break;
349+
}
350+
try_files $uri $try_location;
351+
}
352+
```
353+
354+
Then, you can run:
355+
356+
```
357+
php please static:warm --header="X-Cache-Refresh: 1"
358+
```
359+
360+
#### Warming behind authentication
361+
362+
If your site is protected by HTTP authentication or expects a specific header, you can use `--header` to provide the necessary credentials or tokens so the warm requests are not blocked. For example:
363+
364+
```
365+
php please static:warm --header="Authorization: Bearer your_token"
366+
```
367+
368+
This ensures the cache warming requests are accepted by your backend even when authentication is required.
369+
370+
330371
## Excluding Pages
331372

332373
You may wish to exclude certain URLs from being cached.
@@ -821,4 +862,4 @@ The cache store can be customized in `config/cache.php`.
821862
],
822863
```
823864

824-
By default, running `artisan cache:clear` won't clear Statamic's cache store. To do this, run `php please static:clear`.
865+
By default, running `artisan cache:clear` won't clear Statamic's cache store. To do this, run `php please static:clear`.

0 commit comments

Comments
 (0)