Skip to content

Update Static Caching Docs for Headers CLI argument #1674

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion content/collections/docs/static-caching.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,12 @@ The `static:warm` command supports various arguments:
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`.
* **`--max-requests`**
Limits the number of requests made by the command. Likely makes the most sense to be used alongside the `--uncached` option.
* **`--header`**
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.

For example: `--header="Authorization: Bearer your_token" --header="X-Ignore-Cache: true"`

You can find [practical examples](#custom-headers) of this parameter below.

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

Expand Down Expand Up @@ -327,6 +333,41 @@ class AppServiceProvider
}
```

### Custom headers

The `--headers` option can be used in advanced scenarios to control how the static cache is warmed. Here are some practical examples:

#### Bypassing cache for refreshes with Nginx

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:

```nginx
location / {
if ($http_x_cache_refresh = "1") {
proxy_pass http://127.0.0.1:8000; # your statamic server
break;
}
try_files $uri $try_location;
}
```

Then, you can run:

```
php please static:warm --header="X-Cache-Refresh: 1"
```

#### Warming behind authentication

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:

```
php please static:warm --header="Authorization: Bearer your_token"
```

This ensures the cache warming requests are accepted by your backend even when authentication is required.


## Excluding Pages

You may wish to exclude certain URLs from being cached.
Expand Down Expand Up @@ -798,4 +839,4 @@ The cache store can be customized in `config/cache.php`.
],
```

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