Repository navigation
web: fix static-file caching & root redirects - #3656
Merged
Merged
Conversation
syphar
marked this pull request as ready for review
October 30, 2026 20:59
syphar
force-pushed
the
static-files-hash
branch
from
October 30, 2026 21:58
fa2fc72 to
2d692c1
Compare
GuillaumeGomez
approved these changes
Nov 2, 2026
GuillaumeGomez
temporarily deployed
to
github-pages
November 2, 2026 10:30 — with
GitHub Actions
Inactive
This branch was previously deployed
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.
When deploying #3647 I realized that there is a problem with caching certain static assets.
Generally (before this PR):
/-/static/asset.css?build-slug=12345as URLbuild_static_routerdid set caching headers in a way that the CDN & the browser can cache forever.This worked, but only for all the places where we actually added the build-slug.
We forgot that in
/-/static/chartjs/chart.min.css/-/static/chartjs/chart.min.js/-/static/trigger-rebuild.png/opensearch.xmland/-/static/opensearch.xml/robots.txtand/-/static/robots.txt/favicon.icoand/-/static/favicon.icothat means when we would want to update any of these, we could only purge our CDN, but user browsers would have old versions.
new approach
The new approach here is:
/-/static/{path}will serve static files with CDN only caching. It uses a surrogate key we invalidate on each deploy automatically/-/static/v/{all-assets-hash}/{path}will serve the same files, but _with different caching headers (cache forever in CDN & browser)/robots.txt) will be changed to be temporary redirects, with cdn-only caching.I tried to convert all places to using the assets-hash URL, but even when I forgot a place, it won't break. Worst case is cdn-only caching.
Nice side-effect: if we use relative
@urlor other references in CSS, the browser will request the versioned URL when the CSS file was referenced with version. In one CSS file I changed absolute paths to relative ones because of that.alternatives
The classic alternative to this approach is to include content-hashes in the filenames. This would improve cache ratio even more, but is quite a bit of work, especially rewriting the CSS links.