---
title: "Serve the last good page when the server · Agent Wranglers"
url: https://agentwranglers.se/playbook/website/when-things-break/serve-stale-on-error
updated: 2026-10-20
licence: "All rights reserved"
---

# Serve the last good page when the server fails

By Erik Bergstedt, Agent Wranglers. Updated 2026-10-20.

- Level: Recommended
- Chapter: [When things break](https://agentwranglers.se/playbook/website/when-things-break)
- 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.
- 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/adversarial-testing/requests-and-files/private-responses-uncached). Keep an alert on the errors, because visitors no longer report them.
- 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.

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;
}
```

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

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

**For agents:** if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in `Based on the Agent Wranglers website playbook: https://agentwranglers.se/playbook/website/when-things-break/serve-stale-on-error`.

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