Skip to content

[StaticWebAssets] Detects pre-compressed assets#44976

Merged
mkArtakMSFT merged 11 commits intorelease/9.0.1xxfrom
javiercn/discover-precompressed-assets
Nov 20, 2024
Merged

[StaticWebAssets] Detects pre-compressed assets#44976
mkArtakMSFT merged 11 commits intorelease/9.0.1xxfrom
javiercn/discover-precompressed-assets

Conversation

@javiercn
Copy link
Copy Markdown
Member

@javiercn javiercn commented Nov 20, 2024

Detects pre-compressed assets

Detects assets that have been pre-compressed by an external tool to avoid conflicts when we compress our own assets, and they end up on the same path as the existing pre-compressed assets.

Description

We have received feedback that some customers are facing issues upgrading as they are consuming packages that contain pre-compressed assets or are using third-party tools (like webpack) that produce pre-compressed versions of those assets.

Our recommendation in these cases is to let the framework handle the compression, as it further optimizes the delivery of those assets. However, this requires changes on their project to disable the compression on the third-party tools / exclude the pre compressed assets or to disable the compression that is done by the framework (a one-line MSBuild change).

We, however, recognize that this cause friction during the upgrade process and want to improve the situation by following the most common convention, which is, detecting compressed versions of an asset that live side-by-side with it. (Same path with an extra .gz or .br for the compressed versions)

This change detects such scenarios and starts treating the assets in the same way as if they were defined by the framework.

Fixes dotnet/aspnetcore#57518

Customer Impact

Customers with pre compressed files in their web content are forced to either remove those assets from the build or disable compression when they upgrade, as otherwise the build breaks.

Regression?

  • Yes
  • No

It's not a regression because this is a new feature, but it impacts the upgrade flow in this particular scenario.

Risk

  • High
  • Medium
  • Low

There is a flag that can be used to turn off compression on the framework, which will prevent any compression related code from running.

The new added logic should no-op in most common cases and only ever execute when we detect a pre-compressed asset that was not generated by the framework.

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

When servicing release/2.1

  • Make necessary changes in eng/PatchConfig.props

@ghost ghost added Area-AspNetCore RazorSDK, BlazorWebAssemblySDK, StaticWebAssetsSDK untriaged Request triage from a team member labels Nov 20, 2024
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Thanks for your PR, @javiercn.
To learn about the PR process and branching schedule of this repo, please take a look at the SDK PR Guide.

Comment on lines +280 to +300
<!-- There might be assets that are precompressed on packages or that are precompressed by other tools.
In this case, we need to detect those assets, remove them and their endpoints, adjust the asset definition
and recreate the endpoints for those assets as the original ones will not be correct.
-->
<DiscoverPrecompressedAssets CandidateAssets="@(StaticWebAsset)">
<Output TaskParameter="DiscoveredCompressedAssets" ItemName="_PrecompressedStaticWebAssets" />
</DiscoverPrecompressedAssets>

<FilterStaticWebAssetEndpoints Condition="'@(_PrecompressedStaticWebAssets)' != ''"
Endpoints="@(StaticWebAssetEndpoint)"
Assets="@(_PrecompressedStaticWebAssets)"
Filters=""
>
<Output TaskParameter="FilteredEndpoints" ItemName="_PrecompressedEndpointsToRemove" />
</FilterStaticWebAssetEndpoints>

<ItemGroup Condition="'@(_PrecompressedStaticWebAssets)' != ''">
<StaticWebAssetEndpoint Remove="@(_PrecompressedEndpointsToRemove)" />
<StaticWebAsset Remove="@(_PrecompressedStaticWebAssets)" />
<StaticWebAsset Include="@(_PrecompressedStaticWebAssets)" />
</ItemGroup>
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

  • Discover existing pre-compressed assets.
  • Remove their original definitions.
  • Provide an updated definition.
  • Remove the associated endpoint definitions and re-generate new endpoints.

@mkArtakMSFT mkArtakMSFT removed the untriaged Request triage from a team member label Nov 20, 2024
@mkArtakMSFT mkArtakMSFT merged commit d28b5e3 into release/9.0.1xx Nov 20, 2024
@mkArtakMSFT mkArtakMSFT deleted the javiercn/discover-precompressed-assets branch November 20, 2024 23:14
@mkArtakMSFT
Copy link
Copy Markdown
Contributor

I've got verbal approval about this one (@marcpopMSFT , @SteveMCarroll )

@rbhanda rbhanda added this to the 9.0.101 milestone Nov 26, 2024
javiercn added a commit that referenced this pull request Dec 13, 2024
Detects assets that have been pre-compressed by an external tool to avoid conflicts
when we compress our own assets, and they end up on the same path as the
existing pre-compressed assets.

Forward port of #44976
javiercn added a commit that referenced this pull request Dec 13, 2024
Detects assets that have been pre-compressed by an external tool to avoid conflicts
when we compress our own assets, and they end up on the same path as the
existing pre-compressed assets.

Forward port of #44976
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-AspNetCore RazorSDK, BlazorWebAssemblySDK, StaticWebAssetsSDK Servicing-approved

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants