CompressedStaticFiles.AspNet 2.1.0

dotnet add package CompressedStaticFiles.AspNet --version 2.1.0                
NuGet\Install-Package CompressedStaticFiles.AspNet -Version 2.1.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CompressedStaticFiles.AspNet" Version="2.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CompressedStaticFiles.AspNet --version 2.1.0                
#r "nuget: CompressedStaticFiles.AspNet, 2.1.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install CompressedStaticFiles.AspNet as a Cake Addin
#addin nuget:?package=CompressedStaticFiles.AspNet&version=2.1.0

// Install CompressedStaticFiles.AspNet as a Cake Tool
#tool nuget:?package=CompressedStaticFiles.AspNet&version=2.1.0                

CompressedStaticFiles.AspNet


NuGet version NuGet version NuGet downloads


GitHub license GitHub issues GitHub forks GitHub stars GitHub stars


GithubActionsRelease GithubActionsWIP


Table of Contents

About The Project

This project allows you to serve precompressed files to the browser without having to compress on demand, this is achieved by compressing/encoding your content at build time.

Getting Started

Precompress content

Static nonimage files have to be precompressed using Gzip, Brotli and/or Zstd, 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/.gzip/.zstd (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. You can convert your images using the following tools webp and libavif. The files must have the same filename as the source but with a new file extension (image.jpg would be image.webp for the webp version).

ASP.NET

Add AddCompressedStaticFiles() in your Startup.ConfigureServices() method. Replace UseStaticFiles(); with UseCompressedStaticFiles(); in Startup.Configure(). By default CompressedStaticFiles is configured to allow slightly larger files for some image formats as they can store more pixels per byte, this can be disabled by calling CompressedStaticFileOptions.RemoveImageSubstitutionCostRatio().

Example

An example with Gzip and Brotli can be found in the Example directory. By using this package the Lighthouse mobile performance went from 76 to 98 and the transferred size went from 526 kb to 141 kb.

Acknowledgements

This solution is developed from a clone of AnderssonPeter/CompressedStaticFiles, which was based upon work by @neyromant from the following issue ASP.NET Issue #1584.

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 to build Brotli, Gzip and Zstd compressed CSS and JS files.
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.1.0 1,808 3/13/2024
2.0.0 742 11/14/2023
1.0.0 2,517 10/26/2022