Always Online — Serve Stale Content During Origin Outages
In this tutorial, you'll learn about Always Online. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.
Cloudflare Always Online serves stale cached content to visitors when your origin server is unreachable, transforming a complete outage into a partially functional site. This tutorial explains how Always Online works, how to configure it, and best practices for maximizing its effectiveness.
Why Always Online Matters
Origin outages happen. A server crash, a network cut, or a cloud provider failure can take your site down for minutes or hours. Without Always Online, visitors see error pages or timeouts. With Always Online, Cloudflare serves the most recent cached version of your pages, keeping your site visible and functional even when the origin is dark.
Real-world use: DodaZIP experienced a 45-minute database server failure. During the outage, Always Online served cached versions of the download pages and documentation. Users could still browse and download cached files, and only dynamic features like account login showed errors. The bounce rate during the outage was only 12% compared to an estimated 85% if the entire site returned 503 errors.
Always Online Flow
flowchart LR
REQ[Visitor Request] --> EDGE[Cloudflare Edge]
EDGE --> ORIG{Origin Reachable?}
ORIG -->|Yes| FRESH[Serve fresh from origin]
ORIG -->|No| CACHE{Cached copy exists?}
CACHE -->|Yes| STALE[Serve stale cached copy]
CACHE -->|No| ERROR[503 Service Unavailable]
FRESH --> USER[Deliver to visitor]
STALE --> USER
ERROR --> USER
style EDGE fill:#f90,color:#fff
style STALE fill:#09c,color:#fff
style ERROR fill:#c00,color:#fff
Configuring Always Online
Always Online is enabled under the Network tab in the Cloudflare dashboard.
# Enable Always Online via API
curl -X PATCH https://api.cloudflare.com/client/v4/zones/{zone_id}/settings/always_online \
-H "Authorization: Bearer {api_token}" \
-H "Content-Type: application/json" \
-d '{"value": "on"}'
# Response: {"result": {"id": "always_online", "value": "on", "modified_on": "..."}}
# Verify Always Online status
curl -s https://api.cloudflare.com/client/v4/zones/{zone_id}/settings/always_online \
-H "Authorization: Bearer {api_token}" | jq '.result.value'
# Returns "on" or "off"
How Stale Content Is Served
When the origin goes offline, Cloudflare checks if it has a cached copy of the requested page. If found, it serves that copy with a special header indicating it is stale.
# Check response headers during an Always Online serve
curl -sI https://example.com/page | grep -i "cf-always-online"
# When Always Online is active:
# cf-always-online: true
# cf-cache-status: EXPIRED (served stale content)
# age: 3600 (content is 1 hour stale)
# How long content stays in Always Online cache
# Cloudflare retains cached content for up to 7 days past its TTL for Always Online
# This window gives you time to restore your origin before content expires
Caching Strategy for Always Online
Always Online only works for content that was previously cached. If your cache hit ratio is low, most pages will still show errors during an outage.
# Best practices for maximizing Always Online effectiveness
# 1. Cache HTML pages with short TTL (e.g., 120 seconds)
# 2. Use Cache Rules to cache dynamic-looking pages
# 3. Ensure /robots.txt and /favicon.ico are cached
# 4. Configure Edge Cache TTL in Cache Rules
# Create a Cache Rule to cache HTML pages
# Dashboard > Rules > Cache Rules > Create Rule
# URI: https://example.com/*
# Cache eligibility: Eligible for cache
# Edge TTL: 2 hours
# Origin TTL: 30 minutes
# This ensures even dynamic pages have cached copies for Always Online
Always Online vs Stale-While-Revalidate
Cloudflare supports both Always Online and stale-while-revalidate headers. They serve different purposes.
| Feature | Always Online | stale-while-revalidate |
|---|---|---|
| Trigger | Origin unreachable | Normal operation |
| Content age | Potentially very stale | Fresh within window |
| Purpose | Outage recovery | Performance |
| Configuration | Dashboard toggle | Cache-Control header |
# Configure stale-while-revalidate at origin
# HTTP response header:
Cache-Control: public, max-age=300, stale-while-revalidate=86400
# Cloudflare serves cached content for up to 300 seconds (max-age)
# During the next 86400 seconds, Cloudflare can serve stale content
# while revalidating in the background
FAQ
Practice Questions
- What condition triggers Cloudflare Always Online to serve stale content?
- Why is a high cache hit ratio important for Always Online effectiveness?
- How does Always Online differ from stale-while-revalidate?
Summary
Cloudflare Always Online serves cached content when your origin is unreachable, keeping your site partially functional during outages. It relies on previously cached responses and works best when you have a high cache hit ratio. Use Cache Rules to ensure critical pages are cached even if they contain dynamic elements.
Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro — security-first tools for the modern web.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro