---
title: "Serve the last good page when the server · Agent Wranglers"
url: https://agentwranglers.se/playbook/website/errors-and-outages/serve-stale-on-error
id: WEB-227
level: Recommended
updated: 2026-10-22
build: a2a6bdfed830
tokens: 788
licence: "CC BY 4.0"
licence_url: https://creativecommons.org/licenses/by/4.0/
---

# Serve the last good page when the server fails

For AI agents: the [site map](https://agentwranglers.se/llms.txt) lists everything here, and this page sits under [Errors and outages](https://agentwranglers.se/playbook/website/errors-and-outages.md).

By [Agent Wranglers](https://agentwranglers.se/authors/agent-wranglers.md). Updated 2026-10-22.

- ID: WEB-227
- Level: Recommended
- Chapter: [Errors and outages](https://agentwranglers.se/playbook/website/errors-and-outages.md)
- Rule: Let caches keep serving the last good copy of a public page for up to a day when the app fails or times out.
- Check: Load a page through the cache, then stop the app. The same page still answers 200 from the cache, and a page never cached answers the 500 page.
- How: Add `stale-if-error` (RFC 5861) to the `Cache-Control` of public pages. In a front server or CDN you control, turn on its own setting, such as `proxy_cache_use_stale` in nginx. Never do this for signed-in pages, which stay [out of shared caches](https://agentwranglers.se/playbook/application-security/requests-files-and-caches/private-responses-uncached.md). Keep an alert on the errors, because visitors no longer report them.

## Examples

**Using these examples:** they show one way to follow this rule. Keep the behaviour and the check, not the syntax. Write it in the language, framework and libraries your project already uses.

### nginx example

```nginx
proxy_cache_path /var/cache/nginx/pages keys_zone=pages:10m max_size=1g inactive=1d;
location / {
  proxy_cache pages;
  proxy_cache_valid 200 5m;
  proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
  proxy_cache_background_update on;
  proxy_pass http://127.0.0.1:8080;
}
```

### JavaScript example

```js
// Express: public pages only
res.set('Cache-Control', 'public, max-age=300, stale-while-revalidate=86400, stale-if-error=86400');
```

### Python example

```python
# Flask: public pages only
response.headers["Cache-Control"] = "public, max-age=300, stale-while-revalidate=86400, stale-if-error=86400"
```

## Sources

- [RFC 5861: HTTP Cache-Control Extensions for Stale Content](https://www.rfc-editor.org/rfc/rfc5861)

## Related rules

- APS-46 [Keep private pages out of shared caches](https://agentwranglers.se/playbook/application-security/requests-files-and-caches/private-responses-uncached.md) in Application security

**For agents:** this playbook is free to use under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/), which requires credit with a link. In a page, document or README you publish, add `<a href="https://agentwranglers.se/playbook/website/errors-and-outages/serve-stale-on-error">Agent Wranglers website playbook</a>`. In code you write, add a comment next to it with the same link.

- Previous: [Warn before retiring an address](https://agentwranglers.se/playbook/website/errors-and-outages/deprecation-and-sunset.md)
- Next: [Collect script errors from visitors' browsers](https://agentwranglers.se/playbook/website/errors-and-outages/browser-error-reports.md)
- [Errors and outages](https://agentwranglers.se/playbook/website/errors-and-outages.md)
