Amblem
Furkan Baytekin

What Is `stale-while-revalidate`? A Simple Guide to Faster Web Performance

Stale-while-revalidate caching

What Is `stale-while-revalidate`? A Simple Guide to Faster Web Performance
13
3 minutes

Modern sites need to feel instant. Users shouldn’t wait while your server prepares fresh data. This is where stale-while-revalidate shines. It lets caches serve old content immediately while they fetch a fresh version in the background.

It’s one of the best tricks for fast, resilient web apps.


What Does stale-while-revalidate Do?

You add it inside your Cache-Control header:

Cache-Control: max-age=60, stale-while-revalidate=300

Meaning:

Users get fast responses, and your server updates quietly.


Why It’s So Useful

1. Instant page loads

Even if your API or server is slow at the moment, users see cached content right away.

2. Fewer origin server hits

Your server gets hammered far less, especially during peak traffic.

3. Zero downtime resiliency

If your backend has a hiccup, caches can still serve the stale copy. Your app feels “up” even if something is broken.

4. Perfect for content that updates often

Dashboards, news feeds, product lists… Users get good performance and reasonably fresh data.


How It Works Step by Step

Let’s say:

Cache-Control: max-age=60, stale-while-revalidate=300

User visits at:

This balance gives speed without sacrificing freshness.


Where It’s Most Useful

It’s basically a free performance boost.


Examples

Express.js

js
app.get("/feed", (req, res) => { res.set("Cache-Control", "public, max-age=60, stale-while-revalidate=300"); res.json({ items: [] }); });

Nginx

nginx
add_header Cache-Control "public, max-age=60, stale-while-revalidate=300";

Go

go
w.Header().Set("Cache-Control", "public, max-age=60, stale-while-revalidate=300")

Best Practices


Conclusion

stale-while-revalidate makes your app feel instant while still staying fresh in the background. It’s one of the easiest, most impactful caching optimizations you can apply—especially on CDNs.


Album of the blog:

Suggested Blog Posts