Skip to content

Commit 952f759

Browse files
Copilotjaviercn
andauthored
[Static Web Assets] Remove weak ETag generation for compressed assets (#50291)
* We still emit the weak ETag since it is used during development to map compressed endpoints to uncompressed representations. * We don't emit the weak ETag by default in the Release configuration, but we do so in Debug during build. * AttachWeakETagToCompressedAssetsDuringDevelopment can be used to unconditionally configure this behavior. Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: javiercn <[email protected]> Co-authored-by: Javier Calvarro Nelson <[email protected]>
1 parent f01e8ae commit 952f759

File tree

75 files changed

+11
-12711
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+11
-12711
lines changed

src/StaticWebAssetsSdk/Targets/Microsoft.NET.Sdk.StaticWebAssets.Compression.targets

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ Copyright (c) .NET Foundation. All rights reserved.
168168
<CompressDiscoveredAssetsDuringBuild Condition="$(CompressDiscoveredAssetsDuringBuild) == ''">true</CompressDiscoveredAssetsDuringBuild>
169169
<!-- Support passing in a custom compression level to brotli and respect the old internal flag for blazor -->
170170
<BrotliCompressionLevel Condition="'$(_BlazorBrotliCompressionLevel)' != ''">$(_BlazorBrotliCompressionLevel)</BrotliCompressionLevel>
171+
172+
<!-- Attach weak ETag to compressed assets -->
173+
<AttachWeakETagToCompressedAssetsDuringDevelopment Condition="'$(AttachWeakETagToCompressedAssetsDuringDevelopment)' == '' and '$(Configuration)' == 'Debug'">true</AttachWeakETagToCompressedAssetsDuringDevelopment>
171174
</PropertyGroup>
172175

173176
<PropertyGroup>
@@ -250,6 +253,7 @@ Copyright (c) .NET Foundation. All rights reserved.
250253
<ApplyCompressionNegotiation
251254
CandidateEndpoints="@(StaticWebAssetEndpoint)"
252255
CandidateAssets="@(_CompressionCurrentProjectBuildAssets)"
256+
AttachWeakETagToCompressedAssets="$(AttachWeakETagToCompressedAssetsDuringDevelopment)"
253257
>
254258
<Output TaskParameter="UpdatedEndpoints" ItemName="_UpdatedCompressionBuildEndpoints" />
255259
</ApplyCompressionNegotiation>
@@ -373,8 +377,7 @@ Copyright (c) .NET Foundation. All rights reserved.
373377

374378
<ApplyCompressionNegotiation
375379
CandidateEndpoints="@(StaticWebAssetEndpoint)"
376-
CandidateAssets="@(_CompressionCurrentProjectPublishAssets)"
377-
>
380+
CandidateAssets="@(_CompressionCurrentProjectPublishAssets)">
378381
<Output TaskParameter="UpdatedEndpoints" ItemName="_UpdatedCompressionPublishEndpoints" />
379382
</ApplyCompressionNegotiation>
380383

src/StaticWebAssetsSdk/Tasks/ApplyCompressionNegotiation.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ public class ApplyCompressionNegotiation : Task
1616
[Required]
1717
public ITaskItem[] CandidateAssets { get; set; }
1818

19+
public bool AttachWeakETagToCompressedAssets { get; set; }
20+
1921
[Output]
2022
public ITaskItem[] UpdatedEndpoints { get; set; }
2123

@@ -371,7 +373,7 @@ private void ApplyRelatedEndpointCandidateHeaders(List<StaticWebAssetEndpointRes
371373
Log.LogMessage(MessageImportance.Low, " Adding header '{0}' to related endpoint '{1}'", header.Name, relatedEndpointCandidate.Route);
372374
headers.Add(header);
373375
}
374-
else if (string.Equals(header.Name, "ETag", StringComparison.Ordinal))
376+
else if (AttachWeakETagToCompressedAssets && string.Equals(header.Name, "ETag", StringComparison.Ordinal))
375377
{
376378
// A resource can have multiple ETags. Since the uncompressed resource has an ETag,
377379
// and we are serving the compressed resource from the same URL, we need to update
@@ -386,8 +388,7 @@ private void ApplyRelatedEndpointCandidateHeaders(List<StaticWebAssetEndpointRes
386388
Name = "ETag",
387389
Value = $"W/{header.Value}"
388390
});
389-
}
390-
else if (string.Equals(header.Name, "Content-Type", StringComparison.Ordinal))
391+
}else if (string.Equals(header.Name, "Content-Type", StringComparison.Ordinal))
391392
{
392393
Log.LogMessage(MessageImportance.Low, "Adding Content-Type '{1}' header to related endpoint '{0}'", relatedEndpointCandidate.Route, header.Value);
393394
// Add the Content-Type to make sure it matches the original asset.

0 commit comments

Comments
 (0)