Repository navigation
Cache versioned JSON as immutable - #2227
Open
David Pine (IEvangelist) wants to merge 1 commit into
Open
David Pine (IEvangelist) wants to merge 1 commit into
David Pine (IEvangelist) wants to merge 1 commit into
Conversation
sidebar.json and the locale fallback dictionaries are requested with a content hash in ?v=, so a new version gets a new URL. Serve them with the immutable Cache-Control so browsers stop revalidating them and Front Door can cache them. Limited to JSON so a page link that happens to carry ?v= is never cached as immutable. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
There are no active review issues for the versioned JSON caching change.
No open issues 🎉
What changed in this PR
Updates StaticHost to serve JSON requests with a non-empty ?v= using immutable caching, supporting the versioned API sidebar and locale fallback data introduced in #2213 and #2214.
Changes:
- Applies the existing one-year immutable cache policy to versioned JSON while leaving other caching behavior unchanged.
- Adds tests covering versioned JSON, missing or empty version values, unrelated query parameters, and HTML with
?v=.
| File | Description |
|---|---|
| tests/StaticHost.Tests/SiteFileTests.cs | Adds cache-policy tests for versioned JSON and excluded cases. |
| src/statichost/StaticHost/SiteFiles/SiteFileMiddleware.cs | Uses query parameters to select immutable caching for versioned JSON. |
Review effort: Balanced
Contributor
Frontend HTML artifact readyThe latest frontend build uploaded the This comment updates automatically when a new frontend build artifact is uploaded. |
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.
Summary
#2213 and #2214 request
sidebar.jsonand the locale fallback dictionaries with a content hash in?v=, so a new version always gets a new URL. StaticHost still served them asno-cache, so browsers revalidated them on every use and Front Door wouldn't cache them.StaticHost now sends the immutable
Cache-Control(max-age=31536000, public, immutable, the same as/_astro) for JSON requested with a non-empty?v=. It applies only to JSON, so a page link that happens to carry?v=is never cached as immutable. Nothing else changes.This replaces #2220. With Front Door caching only fingerprinted content (
/_astro/*and?v=URLs) and no purge on deploy, this was the only part of #2220 still needed.Third-party links and affiliations
None
Validation
dotnet test tests/StaticHost.Tests --filter "FullyQualifiedName!~StaticHost.Tests.Live": passed (185/185). The Live tests need Docker and weren't run locally.Versioned_json_is_immutablecases:sidebar.json?v=…andlocale-fallback/de.json?v=…are immutable.v, an emptyv, a different parameter, and HTML with?v=all stayno-cache.