Skip to content

[Static Web Assets] Remove weak ETag generation for compressed assets #50291

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Aug 15, 2025

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 15, 2025

This PR fixes an issue where compressed static web assets were receiving both strong and weak ETags on the same HTTP response, which causes problems in some situations.

Problem

The ApplyCompressionNegotiation task was adding weak ETags (e.g., W/"original-etag") to compressed assets in addition to their own strong ETags (e.g., "compressed-gzip-etag"). This resulted in responses with multiple ETags:

ETag: "sha256-compressed-content-hash"
ETag: W/"sha256-original-content-hash"

Having both strong and weak ETags on the same response can cause issues with HTTP caching and conditional requests in certain scenarios.

Solution

  • Removed the code in ApplyCompressionNegotiation.cs (lines 374-389) that was generating weak ETags from the original asset's ETag
  • Updated unit tests to no longer expect weak ETags in response headers
  • Updated integration tests to remove assertions for weak ETags

Result

Compressed assets now have only their own strong ETag based on the compressed content:

ETag: "sha256-compressed-content-hash"

This eliminates the problematic dual ETag scenario while preserving all caching functionality. The strong ETag from the compressed content is sufficient for proper HTTP cache validation.

Files Changed

  • src/StaticWebAssetsSdk/Tasks/ApplyCompressionNegotiation.cs - Removed weak ETag generation logic
  • test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ApplyCompressionNegotiationTest.cs - Updated test expectations
  • test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssetsCompressionIntegrationTest.cs - Removed weak ETag assertions

Fixes #50290.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

@Copilot Copilot AI changed the title [WIP] [Static Web Assets] Avoid adding an additional weak ETag to compressed assets [Static Web Assets] Remove weak ETag generation for compressed assets Aug 15, 2025
@Copilot Copilot AI requested a review from javiercn August 15, 2025 13:48
Copilot finished work on behalf of javiercn August 15, 2025 13:48
Copy link
Member

Choose a reason for hiding this comment

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

Undo changes to this file.

@javiercn javiercn requested a review from MackinnonBuck August 15, 2025 14:45
@javiercn javiercn marked this pull request as ready for review August 15, 2025 14:50
@Copilot Copilot AI review requested due to automatic review settings August 15, 2025 14:50
@javiercn javiercn requested a review from a team as a code owner August 15, 2025 14:50
Copy link
Contributor

@Copilot Copilot AI left a comment

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 removes the generation of weak ETags for compressed static web assets to eliminate problematic dual ETag responses. Previously, compressed assets received both their own strong ETag and a weak ETag derived from the original asset, which could cause HTTP caching issues.

  • Removes weak ETag generation logic from the compression negotiation task
  • Updates test expectations across unit and integration tests to match the new behavior
  • Preserves strong ETags based on compressed content for proper cache validation

Reviewed Changes

Copilot reviewed 11 out of 73 changed files in this pull request and generated no comments.

File Description
test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/StaticWebAssetsBaselines/StaticWebAssets_Build_Hosted_Works.Build.staticwebassets.json Removes duplicate ETag entries from compressed asset baseline test file
test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/StaticWebAssetsBaselines/StaticWebAssets_BuildMinimal_Works.Build.staticwebassets.json Removes duplicate ETag entries from minimal build baseline test file
test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/StaticWebAssetsBaselines/StaticWebAssets_BackCompatibilityPublish_Hosted_Works.Publish.staticwebassets.json Removes duplicate ETag entries from back compatibility publish baseline test file
test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/StaticWebAssetsBaselines/Publish_DoesNotGenerateManifestJson_IncludesJSModulesOnBlazorBootJsonManifest.Publish.staticwebassets.json Removes duplicate ETag entries from publish baseline test file

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

@javiercn javiercn enabled auto-merge (squash) August 15, 2025 19:35
@javiercn javiercn merged commit 952f759 into main Aug 15, 2025
27 checks passed
@javiercn javiercn deleted the copilot/fix-50290 branch August 15, 2025 21:26
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.

[Static Web Assets] Avoid adding an additional weak ETag to compressed assets
3 participants