Fix cache headers for Blazor resource collection endpoint#65513
Open
Fix cache headers for Blazor resource collection endpoint#65513
Conversation
Copilot
AI
changed the title
[WIP] Add no-transform to cache headers for resource collection endpoint
Add no-transform to cache headers and move Vary to common headers for resource collection endpoint
Feb 23, 2026
Copilot
AI
changed the title
Add no-transform to cache headers and move Vary to common headers for resource collection endpoint
Fix cache headers for Blazor resource collection endpoint
Feb 23, 2026
56792a4 to
18636aa
Compare
…ers for resource collection endpoint Co-authored-by: javiercn <6995051+javiercn@users.noreply.github.com>
Co-authored-by: javiercn <6995051+javiercn@users.noreply.github.com>
18636aa to
eebfee0
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes three HTTP caching header issues for the /_framework/resource-collection.js endpoint in Blazor WebAssembly applications. The changes improve cache correctness and prevent content transformation by intermediaries.
Changes:
- Added
no-transformdirective to Cache-Control headers for both fingerprinted (long-lived) and non-fingerprinted (revalidation-required) variants - Moved
Vary: Accept-Encodingheader from gzip-specific method to common headers method, ensuring all responses properly advertise encoding variance - Simplified gzip ETag from a two-element array (containing incorrect weak ETag) to a single strong ETag computed from gzipped content
Comments suppressed due to low confidence (1)
src/Components/Endpoints/src/Builder/ResourceCollectionUrlEndpoint.cs:275
- The changes to HTTP headers (addition of no-transform, moving Vary header, and ETag simplification) lack test coverage. Consider adding integration tests that verify:
- Cache-Control headers contain "no-transform" for both fingerprinted and non-fingerprinted responses
- Vary: Accept-Encoding is present on all responses (both gzipped and non-gzipped)
- Gzipped responses have a single strong ETag (not multiple ETags)
These headers are critical for correct caching behavior in production environments.
private static void WriteCommonHeaders(HttpContext context, byte[] contents)
{
context.Response.ContentType = "application/javascript";
context.Response.ContentLength = contents.Length;
context.Response.Headers[HeaderNames.Vary] = HeaderNames.AcceptEncoding;
}
ilonatommy
approved these changes
Feb 27, 2026
javiercn
approved these changes
Feb 27, 2026
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.
Fixes three issues with HTTP response headers on the
/_framework/resource-collection.jsendpoint.Description
no-transformadded toCache-Controlon both fingerprinted (max-age=31536000, immutable) and non-fingerprinted (no-cache, must-revalidate) variants — prevents proxies/CDNs from modifying the JS module content.Vary: Accept-Encodingmoved fromWriteEncodingHeaders(gzip-only) toWriteCommonHeaders— ensures all responses (gzip and identity) correctly advertise encoding variance to caches._gzipContentETagswas a two-element array containing a weak variant of the plain-content ETag alongside the gzip strong ETag. The weak ETag is incorrect here; gzip responses now carry only their own strong ETag. This also simplifies the field fromstring[]tostring.Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.