Skip to content

Cache versioned JSON as immutable - #2227

Open
David Pine (IEvangelist) wants to merge 1 commit into
mainfrom
dapine/versioned-urls-immutable
Open

David Pine (IEvangelist) wants to merge 1 commit into
mainfrom
dapine/versioned-urls-immutable

Conversation

@IEvangelist

Copy link
Copy Markdown
Member

Summary

#2213 and #2214 request sidebar.json and the locale fallback dictionaries with a content hash in ?v=, so a new version always gets a new URL. StaticHost still served them as no-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.
  • New Versioned_json_is_immutable cases:
    • sidebar.json?v=… and locale-fallback/de.json?v=… are immutable.
    • No v, an empty v, a different parameter, and HTML with ?v= all stay no-cache.

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>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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

@aspire-repo-bot

Copy link
Copy Markdown
Contributor

Frontend HTML artifact ready

The latest frontend build uploaded the frontend-dist artifact for PR #2227. Use the VS Code button below to open this PR with GitHub Artifacts Explorer and browse the built HTML locally.

VS Code: Open PR #2227 artifacts

This comment updates automatically when a new frontend build artifact is uploaded.

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