Skip to content

fix(website): make stars widget cache stale-while-revalidate#230

Merged
singaraiona merged 1 commit into
masterfrom
fix/gh-stars-stale-while-revalidate
Jun 8, 2026
Merged

fix(website): make stars widget cache stale-while-revalidate#230
singaraiona merged 1 commit into
masterfrom
fix/gh-stars-stale-while-revalidate

Conversation

@singaraiona

Copy link
Copy Markdown
Collaborator

Why

Follow-up to #229. After that merged, the widget source was fresh, but a user reported the count still didn't change even after a hard refresh.

Cause: the widget read its localStorage cache and returned early for up to an hour, never hitting the network. A hard refresh clears the HTTP cache but not localStorage — so a stale count froze for the full hour with no way for a visitor to force an update short of clearing site data.

What

Switch the cache to stale-while-revalidate:

  • Paint the cached value instantly (fast first paint).
  • Then revalidate in the background and repaint only if the count changed (no re-animation of an identical value).
  • Skip the background fetch when the cache is younger than 5 minutes, bounding GitHub API calls to ~12/hour per visitor — comfortably under the 60/hour unauthenticated limit — even across heavy doc browsing.

A stale cache now self-corrects on the next visit instead of freezing for an hour.

Applied to both copies: docs/javascripts/main.js and website/script.js.

Note for existing visitors

Anyone currently stuck on a stale number will self-correct on their next visit once this deploys. The one-time manual reset is localStorage.removeItem('gh-stats:RayforceDB/rayforce') in the console.

🤖 Generated with Claude Code

The widget read its localStorage cache and returned early for up to an
hour, never hitting the network. Because localStorage survives a hard
refresh, a stale count would freeze for the full hour with no way for a
visitor to force an update short of clearing site data.

Switch to stale-while-revalidate: paint the cached value instantly, then
revalidate in the background and repaint only if the count changed. Skip
the background fetch when the cache is younger than 5 minutes, bounding
GitHub API calls to ~12/hour per visitor — well under the 60/hour limit —
even across heavy doc browsing. A stale cache now self-corrects on the
next visit instead of freezing.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@singaraiona singaraiona merged commit 5c842ed into master Jun 8, 2026
7 of 8 checks passed
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