Skip to content

feat: version static assets with deployed git SHA#48

Open
mroderick wants to merge 2 commits into
mainfrom
feature/static-asset-versioning
Open

feat: version static assets with deployed git SHA#48
mroderick wants to merge 2 commits into
mainfrom
feature/static-asset-versioning

Conversation

@mroderick

Copy link
Copy Markdown
Collaborator

Problem

Static assets (/static/auth-client.js) use a manual ?v=N query param for cache busting. Every deploy requires remembering to bump it. Browsers serve stale versions when you forget.

PR #46 adds Bootstrap CSS/JS, custom CSS, and images to static/ — growing the set of files that need versioning.

Solution

Derive a version stamp at app startup from Heroku's built-in env vars:

  1. HEROKU_SLUG_COMMIT — the deployed git SHA, set automatically at runtime
  2. Falls back to SOURCE_VERSION (Heroku build-time env), then dev for local dev

First 7 characters are used as ?v=<sha> on static URLs. Every deploy gets a new version automatically — zero configuration, zero build steps, zero dependencies.

Changes

  • src/app/components/layout.js — added STATIC_VERSION constant, replaced hardcoded ?v=2 with v=${STATIC_VERSION} on the /static/auth-client.js script tag

Usage for new assets

Any future static asset (CSS, images, etc.) in the layout uses ${STATIC_VERSION} in its URL. Example for PR #46's assets:

<link rel="stylesheet" href="/static/bootstrap.min.css?v=${STATIC_VERSION}" />
<link rel="stylesheet" href="/static/codebar.css?v=${STATIC_VERSION}" />

Testing

  • 161/161 tests passing
  • Local dev: falls back to dev when no Heroku env vars are present (no cache busting locally, where it doesn't matter)
  • Heroku: automatically picks up HEROKU_SLUG_COMMIT — every deploy changes the version

Replace the manual ?v=N cache buster on /static/auth-client.js with
an automatic version derived from HEROKU_SLUG_COMMIT (set by Heroku
at runtime). Falls back to SOURCE_VERSION, then 'dev' for local dev.

This ensures browsers re-download static assets after every deploy
without manual version bumps. Ready for future assets (CSS, images)
to use the same STATIC_VERSION in their URLs.
@mroderick
mroderick requested a review from till July 17, 2026 12:08
@mroderick
mroderick marked this pull request as ready for review July 17, 2026 12:08
Fix formatting in admin.js, common.js, and home.js that was committed
before prettier checks were enforced in CI. These are not related to
the versioning feature but block the CI smoke job.
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.

2 participants