fix(website): make stars widget cache stale-while-revalidate#230
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
localStoragecache and returned early for up to an hour, never hitting the network. A hard refresh clears the HTTP cache but notlocalStorage— 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:
A stale cache now self-corrects on the next visit instead of freezing for an hour.
Applied to both copies:
docs/javascripts/main.jsandwebsite/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