Skip to content

fix(cache): prevent CDN from rewriting the home browser TTL - #18

Merged
phatpham9 merged 1 commit into
mainfrom
fix/home-browser-cache-ttl
Nov 13, 2026
Merged

phatpham9 merged 1 commit into
mainfrom
fix/home-browser-cache-ttl

Conversation

@phatpham9

Copy link
Copy Markdown
Member

Problem

Production was returning the home HTML with Cache-Control: max-age=14400, s-maxage=300 even though the Worker sends max-age=0, s-maxage=300. Cloudflare’s CDN cached the response because of s-maxage and the zone’s Browser Cache TTL setting rewrote the browser TTL to four hours. That left the server-rendered feed cacheable in browsers for much longer than the intended five minutes.

Fix

  • Split the cached copy from the client copy in platforms/cloudflare/src/index.ts.
  • The Cache API stores the five-minute copy with Cache-Control: public, max-age=300; the response returned to clients is always Cache-Control: private, no-store on both a cache miss and a Cache API hit.
  • Edge caching still happens explicitly in the Workers Cache API, so the home page remains fast; Cloudflare’s CDN no longer caches the HTML, so its Browser Cache TTL setting cannot rewrite the client header.
  • The service worker’s navigation handler still stores the shell in Cache Storage, so offline reuse is unchanged.
  • Updated README, ARCHITECTURE, DEPLOYMENT, and RUNBOOK.

Verification

  • Local miss and hit both return Cache-Control: private, no-store with Content-Type: text/html; charset=utf-8.
  • D1 probe with a non-dev APP_VERSION: warming /, inserting a new row, then requesting / returned the cached HTML without the new row; a fresh cache key (/?cacheprobe=1) did include it. The internal five-minute Cache API still works.
  • Service worker registration/precache still stores / in reader-shell-v142 with Cache-Control: private, no-store and the full 131 KB HTML, so offline reuse is intact.
  • npm run typecheck
  • npm test — 87 passing
  • npm audit — 0 vulnerabilities
  • wrangler deploy --dry-run

Production verification

After deploy, curl -sI https://reader.boringcode.dev/ should return cache-control: private, no-store and cf-cache-status: BYPASS/DYNAMIC rather than HIT. The Worker Cache API still serves the five-minute copy.

🤖 Generated with Claude Code

Production Cloudflare was caching the home HTML through the CDN and
rewriting Cache-Control max-age=0 to the zone's 4-hour Browser Cache TTL.

- Store the five-minute edge copy in the Cache API with a public max-age
  header, but return a private, no-store response to clients on both cache
  misses and hits
- Keep the Cache API as the edge cache (5 minutes); no CDN caching means the
  zone Browser Cache TTL can no longer rewrite the client header
- The service worker still stores the no-store shell in Cache Storage for
  offline reuse
- Update README/ARCHITECTURE/DEPLOYMENT/RUNBOOK

Verified: client header is private, no-store on miss and hit; a D1 probe
confirmed warm Cache API hits still omit newly inserted rows; the service
worker still caches '/' for offline; typecheck, 87 tests, audit, and
wrangler dry-run pass.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

🔎 Cloudflare preview: https://61477c07-feedreader.phatpham9.workers.dev

Uploaded from 897d198f9aa53a423c047d3514e4566c392b4005. This is a Worker version preview — it shares the production D1 database, so it reads/writes real data; it does not receive cron-triggered refreshes.

@phatpham9
phatpham9 merged commit 82128f3 into main Nov 13, 2026
3 checks passed
@phatpham9
phatpham9 deleted the fix/home-browser-cache-ttl branch November 13, 2026 03:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant