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
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ Copyright (c) .NET Foundation. All rights reserved.
<CompressDiscoveredAssetsDuringBuild Condition="$(CompressDiscoveredAssetsDuringBuild) == ''">true</CompressDiscoveredAssetsDuringBuild>
<!-- Support passing in a custom compression level to brotli and respect the old internal flag for blazor -->
<BrotliCompressionLevel Condition="'$(_BlazorBrotliCompressionLevel)' != ''">$(_BlazorBrotliCompressionLevel)</BrotliCompressionLevel>

<!-- Attach weak ETag to compressed assets -->
<AttachWeakETagToCompressedAssetsDuringDevelopment Condition="'$(AttachWeakETagToCompressedAssetsDuringDevelopment)' == '' and '$(Configuration)' == 'Debug'">true</AttachWeakETagToCompressedAssetsDuringDevelopment>
</PropertyGroup>

<PropertyGroup>
Expand Down Expand Up @@ -250,6 +253,7 @@ Copyright (c) .NET Foundation. All rights reserved.
<ApplyCompressionNegotiation
CandidateEndpoints="@(StaticWebAssetEndpoint)"
CandidateAssets="@(_CompressionCurrentProjectBuildAssets)"
AttachWeakETagToCompressedAssets="$(AttachWeakETagToCompressedAssetsDuringDevelopment)"
>
<Output TaskParameter="UpdatedEndpoints" ItemName="_UpdatedCompressionBuildEndpoints" />
</ApplyCompressionNegotiation>
Expand Down Expand Up @@ -373,8 +377,7 @@ Copyright (c) .NET Foundation. All rights reserved.

<ApplyCompressionNegotiation
CandidateEndpoints="@(StaticWebAssetEndpoint)"
CandidateAssets="@(_CompressionCurrentProjectPublishAssets)"
>
CandidateAssets="@(_CompressionCurrentProjectPublishAssets)">
<Output TaskParameter="UpdatedEndpoints" ItemName="_UpdatedCompressionPublishEndpoints" />
</ApplyCompressionNegotiation>

Expand Down
7 changes: 4 additions & 3 deletions src/StaticWebAssetsSdk/Tasks/ApplyCompressionNegotiation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class ApplyCompressionNegotiation : Task
[Required]
public ITaskItem[] CandidateAssets { get; set; }

public bool AttachWeakETagToCompressedAssets { get; set; }

[Output]
public ITaskItem[] UpdatedEndpoints { get; set; }

Expand Down Expand Up @@ -371,7 +373,7 @@ private void ApplyRelatedEndpointCandidateHeaders(List<StaticWebAssetEndpointRes
Log.LogMessage(MessageImportance.Low, " Adding header '{0}' to related endpoint '{1}'", header.Name, relatedEndpointCandidate.Route);
headers.Add(header);
}
else if (string.Equals(header.Name, "ETag", StringComparison.Ordinal))
else if (AttachWeakETagToCompressedAssets && string.Equals(header.Name, "ETag", StringComparison.Ordinal))
{
// A resource can have multiple ETags. Since the uncompressed resource has an ETag,
// and we are serving the compressed resource from the same URL, we need to update
Expand All @@ -386,8 +388,7 @@ private void ApplyRelatedEndpointCandidateHeaders(List<StaticWebAssetEndpointRes
Name = "ETag",
Value = $"W/{header.Value}"
});
}
else if (string.Equals(header.Name, "Content-Type", StringComparison.Ordinal))
}else if (string.Equals(header.Name, "Content-Type", StringComparison.Ordinal))
{
Log.LogMessage(MessageImportance.Low, "Adding Content-Type '{1}' header to related endpoint '{0}'", relatedEndpointCandidate.Route, header.Value);
// Add the Content-Type to make sure it matches the original asset.
Expand Down
Loading