Skip to content

Set immutable cache headers for _astro/ files at build time - #121

Merged
David Pine (IEvangelist) merged 5 commits into
mainfrom
javiercn/update-cache-headers
Dec 5, 2025
Merged

David Pine (IEvangelist) merged 5 commits into
mainfrom
javiercn/update-cache-headers

Conversation

@javiercn

@javiercn Javier Calvarro Nelson (javiercn) commented Dec 5, 2025 •

Copy link
Copy Markdown
Contributor

This PR uses the UpdateStaticWebAssetEndpoints MSBuild task to set immutable cache headers for Astro's fingerprinted assets (_astro/ files) at build time.

Changes

  • Added Caching.targets with a target that runs after ResolveProjectStaticWebAssets
  • Uses the Replace operation to change Cache-Control: no-cache to max-age=31536000, public, immutable for _astro/ endpoints
  • Updated StaticHost.csproj to import the new targets file

Why

Astro generates fingerprinted assets in the _astro/ folder. These files have content hashes in their names, making them safe to cache indefinitely with immutable headers.

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.

Pull request overview

This PR configures immutable cache headers for Astro's fingerprinted assets at build time using MSBuild's UpdateStaticWebAssetEndpoints task. The change enables aggressive browser caching for content-hashed assets in the _astro/ folder.

Key Changes

  • Created Caching.targets MSBuild file that hooks into the build process after static web assets are resolved
  • Modified endpoint cache headers from no-cache to max-age=31536000, public, immutable for _astro/ paths
  • Integrated the targets file into StaticHost.csproj

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/statichost/StaticHost/StaticHost.csproj Added import statement to include the Caching.targets file in the build process
src/statichost/StaticHost/Caching.targets Implements MSBuild target to filter and update cache headers for _astro/ endpoints using the UpdateStaticWebAssetEndpoints task

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

4 participants