Skip to content

Cache GitHub API stats at build time to avoid rate limits #1

@planetf1

Description

@planetf1

Problem

The useGitHubStats hook fires 4 unauthenticated GitHub API requests on every page load (repo data, latest release, contributor count, contributor avatars). The unauthenticated rate limit is 60 requests/hour per IP — a handful of refreshes or any bot crawl will hit 403s and the stats card will show dashes.

Suggested approach

Fetch GitHub stats once at build time via a CI step or build script, write the result to a JSON file in public/, and have the client component read from that instead. The GitHub Action already has a GITHUB_TOKEN with 5,000 req/hour, so rate limits are not a concern during CI.

Alternatively, use the GitHub GraphQL API to collapse the 4 REST calls into a single request, reducing the per-visitor footprint.

Scope

  • src/hooks/useGitHubStats.ts
  • .github/workflows/nextjs.yml (add pre-build fetch step)
  • New public/github-stats.json (gitignored, generated at build)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions