Skip to content
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

[StaticWebAssets] Optimize compression #47734

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,13 @@ Copyright (c) .NET Foundation. All rights reserved.
</PropertyGroup>

<PropertyGroup>
<BuildCompressionFormats>$(BuildCompressionFormats);gzip</BuildCompressionFormats>
<PublishCompressionFormats>$(PublishCompressionFormats);gzip;brotli</PublishCompressionFormats>
<EnableDefaultCompressionFormats Condition="'$(EnableDefaultCompressionFormats)' == ''">true</EnableDefaultCompressionFormats>
<BuildCompressionFormats Condition="'$(EnableDefaultCompressionFormats)' == 'true'">$(BuildCompressionFormats);gzip</BuildCompressionFormats>
<PublishCompressionFormats Condition="'$(EnableDefaultCompressionFormats)' == 'true'">$(PublishCompressionFormats);gzip;brotli</PublishCompressionFormats>
<DisableBuildCompression Condition="'$(DisableBuildCompression)' == ''">false</DisableBuildCompression>
<CompressionIncludePatterns>$(CompressionIncludePatterns)</CompressionIncludePatterns>
<CompressionExcludePatterns>$(CompressionExcludePatterns)</CompressionExcludePatterns>
<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>
</PropertyGroup>

<PropertyGroup>
Expand Down Expand Up @@ -195,7 +197,7 @@ Copyright (c) .NET Foundation. All rights reserved.
GeneratePublishCompressedStaticWebAssets
ResolvePublishCompressedStaticWebAssetsConfiguration
-->
<ResolvePublishRelatedStaticWebAssetsDependsOn Condition="'$(DisableBuildCompression)' != 'true'">
<ResolvePublishRelatedStaticWebAssetsDependsOn>
ResolvePublishCompressedStaticWebAssets;
$(ResolvePublishRelatedStaticWebAssetsDependsOn)
</ResolvePublishRelatedStaticWebAssetsDependsOn>
Expand Down Expand Up @@ -270,7 +272,7 @@ Copyright (c) .NET Foundation. All rights reserved.

<BrotliCompress Condition="'@(_BrotliCompressedStaticWebAssets)' != ''"
FilesToCompress="@(_BrotliCompressedStaticWebAssets)"
CompressionLevel="$(_BlazorBrotliCompressionLevel)"
CompressionLevel="$(BrotliCompressionLevel)"
ToolAssembly="$(_StaticWebAssetsSdkToolAssembly)"
ToolExe="$(_DotNetHostFileName)"
ToolPath="$(_DotNetHostDirectory)" />
Expand Down Expand Up @@ -304,8 +306,29 @@ Copyright (c) .NET Foundation. All rights reserved.
<StaticWebAsset Include="@(_PrecompressedStaticWebAssets)" />
</ItemGroup>

<PropertyGroup>
<StaticWebAssetBuildCompressAllAssets Condition="'$(StaticWebAssetBuildCompressAllAssets)' == '' and '$(StaticWebAssetProjectMode)' == 'Root'">true</StaticWebAssetBuildCompressAllAssets>
<StaticWebAssetBuildCompressAllAssets Condition="'$(StaticWebAssetBuildCompressAllAssets)' == ''">false</StaticWebAssetBuildCompressAllAssets>
</PropertyGroup>

<ItemGroup Condition="'$(StaticWebAssetBuildCompressAllAssets)' == 'true'">
<_CandidateAssetsForBuild Include="@(StaticWebAsset)" />
</ItemGroup>

<ItemGroup Condition="'$(StaticWebAssetBuildCompressAllAssets)' != 'true'">
<_CandidateAssetsForBuild
Include="@(StaticWebAsset)"
Condition="'%(SourceType)' == 'Discovered' or '%(SourceType)' == 'Computed'" />
</ItemGroup>

<ItemGroup Condition="'$(CompressDiscoveredAssetsDuringBuild)' != 'true'">
<_CandidateAssetsForBuild
Remove="@(_CandidateAssetsForBuild)"
Condition="'%(SourceType)' == 'Discovered'" />
</ItemGroup>

<ResolveCompressedAssets
CandidateAssets="@(StaticWebAsset)"
CandidateAssets="@(_CandidateAssetsForBuild)"
Formats="$(BuildCompressionFormats)"
IncludePatterns="$(CompressionIncludePatterns)"
ExcludePatterns="$(CompressionExcludePatterns)"
Expand Down Expand Up @@ -386,12 +409,23 @@ Copyright (c) .NET Foundation. All rights reserved.

<Target Name="ResolvePublishCompressedStaticWebAssetsConfiguration" DependsOnTargets="ResolvePublishStaticWebAssets;$(ResolveCompressedFilesForPublishDependsOn)">

<ItemGroup>
<PropertyGroup>
<StaticWebAssetPublishCompressAllAssets Condition="'$(StaticWebAssetPublishCompressAllAssets)' == '' and '$(StaticWebAssetProjectMode)' == 'Root'">true</StaticWebAssetPublishCompressAllAssets>
<StaticWebAssetPublishCompressAllAssets Condition="'$(StaticWebAssetPublishCompressAllAssets)' == ''">false</StaticWebAssetPublishCompressAllAssets>
</PropertyGroup>

<ItemGroup Condition="'$(StaticWebAssetPublishCompressAllAssets)' == 'true'">
<_CandidateAssetsForPublish
Include="@(StaticWebAsset)"
Condition="'%(AssetKind)' != 'Build'" />
</ItemGroup>

<ItemGroup Condition="'$(StaticWebAssetPublishCompressAllAssets)' != 'true'">
<_CandidateAssetsForPublish
Include="@(StaticWebAsset)"
Condition="'%(AssetKind)' != 'Build' and ('%(SourceType)' == 'Discovered' or '%(SourceType)' == 'Computed')" />
</ItemGroup>

<ResolveCompressedAssets
CandidateAssets="@(_CandidateAssetsForPublish)"
Formats="$(PublishCompressionFormats)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -717,10 +717,23 @@ Copyright (c) .NET Foundation. All rights reserved.
<Output TaskParameter="OriginalAssets" ItemName="_OriginalPackageAssets" />
</UpdatePackageStaticWebAssets>

<ItemGroup>
<_AssetsWithoutEndpoints Include="@(_UpdatedPackageAssets)" Exclude="@(StaticWebAssetEndpoint->'%(AssetFile)')" />
</ItemGroup>

<DefineStaticWebAssetEndpoints
CandidateAssets="@(_AssetsWithoutEndpoints)"
ContentTypeMappings="@(StaticWebAssetContentTypeMapping)"
>
<Output TaskParameter="Endpoints" ItemName="_UpdatedPackageAssetsEndpoint" />
</DefineStaticWebAssetEndpoints>

<ItemGroup>
<StaticWebAsset Remove="@(_OriginalPackageAssets)"/>
<StaticWebAsset Include="@(_UpdatedPackageAssets)" />
<StaticWebAssetEndpoint Include="@(_UpdatedPackageAssetsEndpoint)" />
</ItemGroup>

</Target>

<Import Project="Microsoft.NET.Sdk.StaticWebAssets.Publish.targets" />
Expand Down
2 changes: 2 additions & 0 deletions src/WebSdk/Web/Targets/Sdk.Server.props
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Copyright (c) .NET Foundation. All rights reserved.
<!-- Default properties that shouldn't be replaced by the microsoft.net.sdk.props -->
<PropertyGroup>
<DebugSymbols Condition="'$(DebugSymbols)' == ''">true</DebugSymbols>
<StaticWebAssetProjectMode>Root</StaticWebAssetProjectMode>
<StaticWebAssetBasePath>/</StaticWebAssetBasePath>
</PropertyGroup>

<Import Sdk="Microsoft.NET.Sdk" Project="Sdk.props" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"Version": 1,
"Hash": "__hash__",
"Source": "blazorhosted",
"BasePath": "_content/blazorhosted",
"Mode": "Default",
"BasePath": "/",
"Mode": "Root",
"ManifestType": "Build",
"ReferencedProjectsConfiguration": [
{
Expand Down Expand Up @@ -47,11 +47,11 @@
],
"Assets": [
{
"Identity": "${ProjectPath}\\blazorhosted\\obj\\Debug\\${Tfm}\\compressed\\_content\\blazorhosted\\blazorhosted.modules.json.gz",
"Identity": "${ProjectPath}\\blazorhosted\\obj\\Debug\\${Tfm}\\compressed\\blazorhosted.modules.json.gz",
"SourceId": "blazorhosted",
"SourceType": "Computed",
"ContentRoot": "${ProjectPath}\\blazorhosted\\obj\\Debug\\${Tfm}\\compressed\\",
"BasePath": "_content/blazorhosted",
"BasePath": "/",
"RelativePath": "blazorhosted.modules.json.gz",
"AssetKind": "Build",
"AssetMode": "CurrentProject",
Expand All @@ -65,7 +65,7 @@
"Integrity": "__integrity__",
"CopyToOutputDirectory": "Never",
"CopyToPublishDirectory": "PreserveNewest",
"OriginalItemSpec": "${ProjectPath}\\blazorhosted\\obj\\Debug\\${Tfm}\\jsmodules\\_content\\blazorhosted\\blazorhosted.modules.json.gz",
"OriginalItemSpec": "${ProjectPath}\\blazorhosted\\obj\\Debug\\${Tfm}\\jsmodules\\blazorhosted.modules.json.gz",
"FileLength": -1,
"LastWriteTime": "0001-01-01T00:00:00+00:00"
},
Expand All @@ -74,7 +74,7 @@
"SourceId": "blazorhosted",
"SourceType": "Computed",
"ContentRoot": "${ProjectPath}\\blazorhosted\\obj\\Debug\\${Tfm}\\jsmodules\\",
"BasePath": "_content/blazorhosted",
"BasePath": "/",
"RelativePath": "blazorhosted.modules.json",
"AssetKind": "Build",
"AssetMode": "CurrentProject",
Expand Down Expand Up @@ -10078,7 +10078,7 @@
"Endpoints": [
{
"Route": "blazorhosted.modules.json.gz",
"AssetFile": "${ProjectPath}\\blazorhosted\\obj\\Debug\\${Tfm}\\compressed\\_content\\blazorhosted\\blazorhosted.modules.json.gz",
"AssetFile": "${ProjectPath}\\blazorhosted\\obj\\Debug\\${Tfm}\\compressed\\blazorhosted.modules.json.gz",
"Selectors": [],
"ResponseHeaders": [
{
Expand Down Expand Up @@ -10123,7 +10123,7 @@
},
{
"Route": "blazorhosted.modules.json",
"AssetFile": "${ProjectPath}\\blazorhosted\\obj\\Debug\\${Tfm}\\compressed\\_content\\blazorhosted\\blazorhosted.modules.json.gz",
"AssetFile": "${ProjectPath}\\blazorhosted\\obj\\Debug\\${Tfm}\\compressed\\blazorhosted.modules.json.gz",
"Selectors": [
{
"Name": "Content-Encoding",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@
"${OutputPath}\\wwwroot\\serviceworkers\\my-service-worker.js",
"${OutputPath}\\wwwroot\\serviceworkers\\my-service-worker.js.br",
"${OutputPath}\\wwwroot\\serviceworkers\\my-service-worker.js.gz",
"${ProjectPath}\\blazorhosted\\obj\\Debug\\${Tfm}\\compressed\\publish\\_content\\blazorhosted\\blazorhosted.modules.json.br",
"${ProjectPath}\\blazorhosted\\obj\\Debug\\${Tfm}\\compressed\\publish\\_content\\blazorhosted\\blazorhosted.modules.json.gz",
"${ProjectPath}\\blazorhosted\\obj\\Debug\\${Tfm}\\compressed\\publish\\blazorhosted.modules.json.br",
"${ProjectPath}\\blazorhosted\\obj\\Debug\\${Tfm}\\compressed\\publish\\blazorhosted.modules.json.gz",
"${ProjectPath}\\blazorhosted\\obj\\Debug\\${Tfm}\\jsmodules\\jsmodules.publish.manifest.json",
"${OutputPath}\\wwwroot\\Fake-License.txt",
"${OutputPath}\\wwwroot\\Fake-License.txt.br",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"Version": 1,
"Hash": "__hash__",
"Source": "blazorhosted",
"BasePath": "_content/blazorhosted",
"Mode": "Default",
"BasePath": "/",
"Mode": "Root",
"ManifestType": "Publish",
"ReferencedProjectsConfiguration": [
{
Expand Down Expand Up @@ -47,11 +47,11 @@
],
"Assets": [
{
"Identity": "${ProjectPath}\\blazorhosted\\obj\\Debug\\${Tfm}\\compressed\\publish\\_content\\blazorhosted\\blazorhosted.modules.json.br",
"Identity": "${ProjectPath}\\blazorhosted\\obj\\Debug\\${Tfm}\\compressed\\publish\\blazorhosted.modules.json.br",
"SourceId": "blazorhosted",
"SourceType": "Computed",
"ContentRoot": "${ProjectPath}\\blazorhosted\\obj\\Debug\\${Tfm}\\compressed\\publish\\",
"BasePath": "_content/blazorhosted",
"BasePath": "/",
"RelativePath": "blazorhosted.modules.json.br",
"AssetKind": "Publish",
"AssetMode": "CurrentProject",
Expand All @@ -65,16 +65,16 @@
"Integrity": "__integrity__",
"CopyToOutputDirectory": "Never",
"CopyToPublishDirectory": "PreserveNewest",
"OriginalItemSpec": "${ProjectPath}\\blazorhosted\\obj\\Debug\\${Tfm}\\jsmodules\\_content\\blazorhosted\\blazorhosted.modules.json.br",
"OriginalItemSpec": "${ProjectPath}\\blazorhosted\\obj\\Debug\\${Tfm}\\jsmodules\\blazorhosted.modules.json.br",
"FileLength": -1,
"LastWriteTime": "0001-01-01T00:00:00+00:00"
},
{
"Identity": "${ProjectPath}\\blazorhosted\\obj\\Debug\\${Tfm}\\compressed\\publish\\_content\\blazorhosted\\blazorhosted.modules.json.gz",
"Identity": "${ProjectPath}\\blazorhosted\\obj\\Debug\\${Tfm}\\compressed\\publish\\blazorhosted.modules.json.gz",
"SourceId": "blazorhosted",
"SourceType": "Computed",
"ContentRoot": "${ProjectPath}\\blazorhosted\\obj\\Debug\\${Tfm}\\compressed\\publish\\",
"BasePath": "_content/blazorhosted",
"BasePath": "/",
"RelativePath": "blazorhosted.modules.json.gz",
"AssetKind": "Publish",
"AssetMode": "CurrentProject",
Expand All @@ -88,7 +88,7 @@
"Integrity": "__integrity__",
"CopyToOutputDirectory": "Never",
"CopyToPublishDirectory": "PreserveNewest",
"OriginalItemSpec": "${ProjectPath}\\blazorhosted\\obj\\Debug\\${Tfm}\\jsmodules\\_content\\blazorhosted\\blazorhosted.modules.json.gz",
"OriginalItemSpec": "${ProjectPath}\\blazorhosted\\obj\\Debug\\${Tfm}\\jsmodules\\blazorhosted.modules.json.gz",
"FileLength": -1,
"LastWriteTime": "0001-01-01T00:00:00+00:00"
},
Expand All @@ -97,7 +97,7 @@
"SourceId": "blazorhosted",
"SourceType": "Computed",
"ContentRoot": "${ProjectPath}\\blazorhosted\\obj\\Debug\\${Tfm}\\jsmodules\\",
"BasePath": "_content/blazorhosted",
"BasePath": "/",
"RelativePath": "blazorhosted.modules.json",
"AssetKind": "Publish",
"AssetMode": "CurrentProject",
Expand Down Expand Up @@ -5777,7 +5777,7 @@
"Endpoints": [
{
"Route": "blazorhosted.modules.json.br",
"AssetFile": "${ProjectPath}\\blazorhosted\\obj\\Debug\\${Tfm}\\compressed\\publish\\_content\\blazorhosted\\blazorhosted.modules.json.br",
"AssetFile": "${ProjectPath}\\blazorhosted\\obj\\Debug\\${Tfm}\\compressed\\publish\\blazorhosted.modules.json.br",
"Selectors": [],
"ResponseHeaders": [
{
Expand Down Expand Up @@ -5822,7 +5822,7 @@
},
{
"Route": "blazorhosted.modules.json",
"AssetFile": "${ProjectPath}\\blazorhosted\\obj\\Debug\\${Tfm}\\compressed\\publish\\_content\\blazorhosted\\blazorhosted.modules.json.br",
"AssetFile": "${ProjectPath}\\blazorhosted\\obj\\Debug\\${Tfm}\\compressed\\publish\\blazorhosted.modules.json.br",
"Selectors": [
{
"Name": "Content-Encoding",
Expand Down Expand Up @@ -5877,7 +5877,7 @@
},
{
"Route": "blazorhosted.modules.json.gz",
"AssetFile": "${ProjectPath}\\blazorhosted\\obj\\Debug\\${Tfm}\\compressed\\publish\\_content\\blazorhosted\\blazorhosted.modules.json.gz",
"AssetFile": "${ProjectPath}\\blazorhosted\\obj\\Debug\\${Tfm}\\compressed\\publish\\blazorhosted.modules.json.gz",
"Selectors": [],
"ResponseHeaders": [
{
Expand Down Expand Up @@ -5922,7 +5922,7 @@
},
{
"Route": "blazorhosted.modules.json",
"AssetFile": "${ProjectPath}\\blazorhosted\\obj\\Debug\\${Tfm}\\compressed\\publish\\_content\\blazorhosted\\blazorhosted.modules.json.gz",
"AssetFile": "${ProjectPath}\\blazorhosted\\obj\\Debug\\${Tfm}\\compressed\\publish\\blazorhosted.modules.json.gz",
"Selectors": [
{
"Name": "Content-Encoding",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"Version": 1,
"Hash": "__hash__",
"Source": "BlazorWasmHosted60.Server",
"BasePath": "_content/BlazorWasmHosted60.Server",
"Mode": "Default",
"BasePath": "/",
"Mode": "Root",
"ManifestType": "Publish",
"ReferencedProjectsConfiguration": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"Version": 1,
"Hash": "__hash__",
"Source": "blazorhosted",
"BasePath": "_content/blazorhosted",
"Mode": "Default",
"BasePath": "/",
"Mode": "Root",
"ManifestType": "Publish",
"ReferencedProjectsConfiguration": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"Version": 1,
"Hash": "__hash__",
"Source": "blazorhosted",
"BasePath": "_content/blazorhosted",
"Mode": "Default",
"BasePath": "/",
"Mode": "Root",
"ManifestType": "Build",
"ReferencedProjectsConfiguration": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"Version": 1,
"Hash": "__hash__",
"Source": "blazorhosted",
"BasePath": "_content/blazorhosted",
"Mode": "Default",
"BasePath": "/",
"Mode": "Root",
"ManifestType": "Build",
"ReferencedProjectsConfiguration": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"Version": 1,
"Hash": "__hash__",
"Source": "blazorhosted",
"BasePath": "_content/blazorhosted",
"Mode": "Default",
"BasePath": "/",
"Mode": "Root",
"ManifestType": "Publish",
"ReferencedProjectsConfiguration": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"Version": 1,
"Hash": "__hash__",
"Source": "blazorhosted",
"BasePath": "_content/blazorhosted",
"Mode": "Default",
"BasePath": "/",
"Mode": "Root",
"ManifestType": "Publish",
"ReferencedProjectsConfiguration": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[
"${ProjectPath}\\AppWithPackageAndP2PReference\\obj\\Debug\\${Tfm}\\compressed\\_content\\AppWithPackageAndP2PReference\\AppWithPackageAndP2PReference#[.{fingerprint=__fingerprint__}]?.styles.css.gz",
"${ProjectPath}\\AppWithPackageAndP2PReference\\obj\\Debug\\${Tfm}\\compressed\\AppWithPackageAndP2PReference#[.{fingerprint=__fingerprint__}]?.styles.css.gz",
"${ProjectPath}\\AppWithPackageAndP2PReference\\obj\\Debug\\${Tfm}\\scopedcss\\bundle\\AppWithPackageAndP2PReference.styles.css"
]
Loading