diff --git a/.github/workflows/GithubActionsRelease.yml b/.github/workflows/GithubActionsRelease.yml index ac9d8a8..bfd7821 100644 --- a/.github/workflows/GithubActionsRelease.yml +++ b/.github/workflows/GithubActionsRelease.yml @@ -59,7 +59,7 @@ jobs: - name: Use prelease dotnet uses: actions/setup-dotnet@v2 with: - dotnet-version: '7.0.x' + dotnet-version: '8.x' include-prerelease: true - name: Get the version diff --git a/.github/workflows/GithubActionsWIP.yml b/.github/workflows/GithubActionsWIP.yml index 20c44da..fdbe25d 100644 --- a/.github/workflows/GithubActionsWIP.yml +++ b/.github/workflows/GithubActionsWIP.yml @@ -38,7 +38,7 @@ jobs: - name: Use prelease dotnet uses: actions/setup-dotnet@v2 with: - dotnet-version: '7.0.x' + dotnet-version: '8.x' include-prerelease: true - name: Build CompressedStaticFiles.AspNetCore 🔧 diff --git a/.gitignore b/.gitignore index d91ff1c..abad702 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,8 @@ bld/ [Bb]in/ [Oo]bj/ +.artifacts/ +PublishedExample/ # Visual Studio 2015 cache/options directory .vs/ diff --git a/CompressedStaticFiles.AspNet.Tests/CompressedStaticFiles.AspNet.Tests.csproj b/CompressedStaticFiles.AspNet.Tests/CompressedStaticFiles.AspNet.Tests.csproj index b1b1f41..1ed723f 100644 --- a/CompressedStaticFiles.AspNet.Tests/CompressedStaticFiles.AspNet.Tests.csproj +++ b/CompressedStaticFiles.AspNet.Tests/CompressedStaticFiles.AspNet.Tests.csproj @@ -1,22 +1,21 @@  - net7.0; true false - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/CompressedStaticFiles.AspNet.sln b/CompressedStaticFiles.AspNet.sln index 9690e70..dda7a88 100644 --- a/CompressedStaticFiles.AspNet.sln +++ b/CompressedStaticFiles.AspNet.sln @@ -9,9 +9,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution .gitignore = .gitignore .github\ISSUE_TEMPLATE\bug_report.md = .github\ISSUE_TEMPLATE\bug_report.md .github\dependabot.yml = .github\dependabot.yml + Directory.Build.props = Directory.Build.props .github\workflows\GithubActionsRelease.yml = .github\workflows\GithubActionsRelease.yml .github\workflows\GithubActionsWIP.yml = .github\workflows\GithubActionsWIP.yml LICENSE = LICENSE + LocalBuild.cmd = LocalBuild.cmd README.md = README.md ReleaseNotes.md = ReleaseNotes.md EndProjectSection diff --git a/CompressedStaticFiles.AspNet/CompressedStaticFiles.AspNet.csproj b/CompressedStaticFiles.AspNet/CompressedStaticFiles.AspNet.csproj index 6931829..f1c62f8 100644 --- a/CompressedStaticFiles.AspNet/CompressedStaticFiles.AspNet.csproj +++ b/CompressedStaticFiles.AspNet/CompressedStaticFiles.AspNet.csproj @@ -1,8 +1,7 @@  - net7.0; - 1.0.0 + 2.0.0 Simon Ziegler;Mark Stega;Peter Andersson;Andrey Kudashkin;Mathias Raacke,Arian Kadkhoda Simon Ziegler;Mark Stega;Peter Andersson;Andrey Kudashkin;Mathias Raacke,Arian Kadkhoda diff --git a/CompressedStaticFiles.Example/CompressedStaticFiles.Example.csproj b/CompressedStaticFiles.Example/CompressedStaticFiles.Example.csproj index c282a53..d940cb2 100644 --- a/CompressedStaticFiles.Example/CompressedStaticFiles.Example.csproj +++ b/CompressedStaticFiles.Example/CompressedStaticFiles.Example.csproj @@ -1,7 +1,6 @@  - net7.0 enable enable @@ -10,67 +9,11 @@ - - - + - - - - <_SDKRoot>$(ILLinkTasksAssembly.Substring(0,$(ILLinkTasksAssembly.LastIndexOf('Microsoft.NET.ILLink.Tasks')))) - $(_SDKRoot)Microsoft.NET.Sdk.BlazorWebAssembly\ - - - <_BlazorWebAssemblySdkTasksAssembly>$(BlazorWebAssemblySdkDirectoryRoot)tools\net472\Microsoft.NET.Sdk.BlazorWebAssembly.Tasks.dll - <_BlazorWebAssemblySdkToolAssembly>$(BlazorWebAssemblySdkDirectoryRoot)tools\$(TargetFramework)\Microsoft.NET.Sdk.BlazorWebAssembly.Tool.dll + $(CompressionIncludePatterns);**/*.css;**/*.js + gzip;brotli + gzip;brotli - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/CompressedStaticFiles.Example/Pages/Index.razor b/CompressedStaticFiles.Example/Pages/Index.razor index 00f316a..f640fff 100644 --- a/CompressedStaticFiles.Example/Pages/Index.razor +++ b/CompressedStaticFiles.Example/Pages/Index.razor @@ -26,6 +26,10 @@

How to detect file compression

+

+ To demonstrate the compressed files execute the 'LocalBuild.cmd' at the root of this repository and follow + the instructions to browse to the demonstration. +

Press F12 to enter your browser's development tools and select the network tab (we did this on Edge here). Click any css or js file (except for blazor.server.js, which as an ASP.NET framework file isn't compressed) @@ -43,71 +47,12 @@


-    <PropertyGroup>
-        <!--Paths to tools, tasks, and extensions are calculated relative to the BlazorWebAssemblySdkDirectoryRoot.
-            But there does not seem to be a property for that, so after much trial and error, using the property 
-            ILLinkTasksAssembly seems most reliable as it contains the same value whether the build is run from VS 
-            or the command line, unlike many others such as MSBuildSDKsPath.
-            If a better property is identified, this can be changed.            
-        -->
-
-        <!-- First, we strip the property value back to the root SDKs level and then down into the WebAssembly SDK -->
-        <_SDKRoot>$(ILLinkTasksAssembly.Substring(0,$(ILLinkTasksAssembly.LastIndexOf('Microsoft.NET.ILLink.Tasks'))))</_SDKRoot>
-        <BlazorWebAssemblySdkDirectoryRoot>$(_SDKRoot)\Microsoft.NET.Sdk.BlazorWebAssembly\</BlazorWebAssemblySdkDirectoryRoot>
-
-        <!-- The next four lines are Copyright (c) .NET Foundation. All rights reserved. -->
-        <_BlazorWebAssemblySdkTasksTFM Condition=" '$(MSBuildRuntimeType)' == 'Core'">net6.0</_BlazorWebAssemblySdkTasksTFM>
-        <_BlazorWebAssemblySdkTasksTFM Condition=" '$(MSBuildRuntimeType)' != 'Core'">net472</_BlazorWebAssemblySdkTasksTFM>
-        <_BlazorWebAssemblySdkTasksAssembly>$(BlazorWebAssemblySdkDirectoryRoot)tools\$(_BlazorWebAssemblySdkTasksTFM)\Microsoft.NET.Sdk.BlazorWebAssembly.Tasks.dll</_BlazorWebAssemblySdkTasksAssembly>
-        <_BlazorWebAssemblySdkToolAssembly>$(BlazorWebAssemblySdkDirectoryRoot)tools\net6.0\Microsoft.NET.Sdk.BlazorWebAssembly.Tool.dll</_BlazorWebAssemblySdkToolAssembly>
-    </PropertyGroup>
-
-    <!-- The next two lines are Copyright (c) .NET Foundation. All rights reserved. -->
-    <UsingTask TaskName="Microsoft.NET.Sdk.BlazorWebAssembly.BrotliCompress" AssemblyFile="$(_BlazorWebAssemblySdkTasksAssembly)" />
-    <UsingTask TaskName="Microsoft.NET.Sdk.BlazorWebAssembly.GzipCompress" AssemblyFile="$(_BlazorWebAssemblySdkTasksAssembly)" />
-
-
-
-
-    <!--
-        This target runs after build. If you want to run after Publish, change:
-        - AfterTargets should be set to "Build"
-        - "ProjectDir" in MyStaticFiles should be changed to "PublishDir"
-    -->
-    <Target Name="CustomGZipAndBrotliCompression" AfterTargets="Build">
-
-        <!--************* THIS IS WHERE YOU CHOOSE WHAT TO COMPRESS *****************
-            you probably don't want to change anything else - just this ItemGroup-->
-
-        <ItemGroup>
-            <MyStaticFiles Include="$(ProjectDir)/wwwroot/**/*.css" />
-            <MyStaticFiles Include="$(ProjectDir)/wwwroot/**/*.js" />
-        </ItemGroup>
-
-        <!--Call the BlazorWebAssembly Task GZipCompress and store the results in MyCompressedFiles-->
-        <GZipCompress FilesToCompress="@@(MyStaticFiles)" OutputDirectory="$(IntermediateOutputPath)compress\">
-            <Output TaskParameter="CompressedFiles" ItemName="MyCompressedFiles" />
-        </GZipCompress>
-
-        <!--Call the BlazorWebAssembly Task BrotliCompress and store the results in MyCompressedFiles-->
-        <BrotliCompress OutputDirectory="$(IntermediateOutputPath)compress\" FilesToCompress="@@(MyStaticFiles)" ToolAssembly="$(_BlazorWebAssemblySdkToolAssembly)" ToolExe="$(_RazorSdkDotNetHostFileName)" ToolPath="$(_RazorSdkDotNetHostDirectory)">
-            <Output TaskParameter="CompressedFiles" ItemName="MyCompressedFiles" />
-        </BrotliCompress>
-
-        <!--Log what we have done-->
-        <Message Importance="High" Text="======= Brotli/GZip Compression For @@(MyCompressedFiles->Count()) Static Files =======" />
-        <Message Importance="High" Text=" Compressed: %(MyCompressedFiles.OriginalItemSpec)%(MyCompressedFiles.Extension)" />
-
-        <!--Rename/move the compressed files back to to the correct place/names as they have "hashed" names at this stage.-->
-        <Move SourceFiles="%(MyCompressedFiles.FullPath)" DestinationFiles="%(MyCompressedFiles.OriginalItemSpec)%(MyCompressedFiles.Extension)" />
-
-    </Target>
-    <ItemGroup>
-        <ProjectReference Include="..\CompressedStaticFiles.AspNetCore\CompressedStaticFiles.AspNetCore.csproj" />
-    </ItemGroup>
-    <ItemGroup>
-        <Folder Include="wwwroot\images\" />
-    </ItemGroup>
+	
+	<PropertyGroup>
+		<CompressionIncludePatterns>$(CompressionIncludePatterns);**/*.css;**/*.js</CompressionIncludePatterns>
+		<BuildCompressionFormats>gzip;brotli</BuildCompressionFormats>
+		<PublishCompressionFormats>gzip;brotli</<PublishCompressionFormats>
+	</PropertyGroup>
 

Attribution

@@ -115,5 +60,4 @@

Thanks to the following:

diff --git a/Directory.Build.props b/Directory.Build.props new file mode 100644 index 0000000..6189363 --- /dev/null +++ b/Directory.Build.props @@ -0,0 +1,16 @@ + + + $(MSBuildThisFileDirectory).artifacts + + + + net8.0 + disable + disable + + + + false + + + diff --git a/LocalBuild.cmd b/LocalBuild.cmd new file mode 100644 index 0000000..ac75a4a --- /dev/null +++ b/LocalBuild.cmd @@ -0,0 +1,21 @@ +@echo off +set argDestination=%1 +if "%1" == "" set argDestination=PublishedExample + +echo Destination is %argDestination% +echo ... +echo Beginning publish +echo ... +dotnet publish CompressedStaticFiles.Example/CompressedStaticFiles.Example.csproj --configuration Debug --output %argDestination% +echo ... +echo Build results +echo ... +dir "%argDestination%" /s +echo ... +echo Executing published example +echo ... +cd %argDestination% +compressedstaticfiles.example.exe" +cd .. +rd %argDestination% /s /q +pause diff --git a/README.md b/README.md index c254fdc..66da304 100644 --- a/README.md +++ b/README.md @@ -41,8 +41,8 @@ This project allows you to serve precompressed files to the browser without havi ## Getting Started ### Precompress content -Static nonimage files have to be precompressed using [Gzip](https://en.wikipedia.org/wiki/Gzip) and/or [Brotli](https://en.wikipedia.org/wiki/Brotli), see the example CompressedStaticFiles.csproj for an automated methodology for producing compressed css & js files. -The files must have the exact same filename as the source + `.br` or `.gzip` (`index.html` would be `index.html.br` for the Brotli version). +Static nonimage files have to be precompressed using [Gzip](https://en.wikipedia.org/wiki/Gzip) and/or [Brotli](https://en.wikipedia.org/wiki/Brotli), see CompressedStaticFiles.Example.csproj for an automated methodology for producing compressed css & js files. +The files must have the same filename as the source + `.br` or `.gzip` (`index.html` would be `index.html.br` for the Brotli version). ### Encode images Modern browsers support new image formats like webp and avif they can store more pixels per byte. @@ -67,4 +67,4 @@ We built this cloned project because: - We wanted to update to the currently supported version of .NET; - To make some refinements that were to our taste; and -- To add MSBuild code to the [example CSPROJ file](https://github.com/Material-Blazor/CompressedStaticFiles.AspNet/blob/main/CompressedStaticFiles.Example/CompressedStaticFiles.Example.csproj#L37) to build Brotli and Gzip compressed CSS and JS files, using a method contributed by [SQL-MisterMagoo](https://github.com/SQL-MisterMagoo). \ No newline at end of file +- To add MSBuild code to the [example CSPROJ file](https://github.com/Material-Blazor/CompressedStaticFiles.AspNet/blob/main/CompressedStaticFiles.Example/CompressedStaticFiles.Example.csproj#L13) to build Brotli and Gzip compressed CSS and JS files. \ No newline at end of file diff --git a/ReleaseNotes.md b/ReleaseNotes.md index c2695e0..e6ee1bf 100644 --- a/ReleaseNotes.md +++ b/ReleaseNotes.md @@ -5,6 +5,19 @@ title: ReleaseNotes # Release Notes +#### [2.0.0](https://github.com/Material-Blazor/CompressedStaticFiles.AspNet/tree/2.0.0) + +Released 2023-11-14 + +**Updates** +- .Net 8.0 +- Example uses MSBuild to produce compressed static files when published +- LocalBuild.cmd introduced to perform a local publish/run for demonstration purposes + +**Breaking Changes** + +**Known issues** + #### [1.0.0](https://github.com/Material-Blazor/CompressedStaticFiles.AspNet/tree/1.0.0) Released 2022-10-26