Soenneker.Css.Minify
11.0.203
Prefix Reserved
dotnet add package Soenneker.Css.Minify --version 11.0.203
NuGet\Install-Package Soenneker.Css.Minify -Version 11.0.203
<PackageReference Include="Soenneker.Css.Minify" Version="11.0.203" />
<PackageVersion Include="Soenneker.Css.Minify" Version="11.0.203" />
<PackageReference Include="Soenneker.Css.Minify" />
paket add Soenneker.Css.Minify --version 11.0.203
#r "nuget: Soenneker.Css.Minify, 11.0.203"
#:package Soenneker.Css.Minify@11.0.203
#addin nuget:?package=Soenneker.Css.Minify&version=11.0.203
#tool nuget:?package=Soenneker.Css.Minify&version=11.0.203
Soenneker.Css.Minify
A CSS text and file minifier powered by Soenneker.Esbuild.Util.
Installation
dotnet add package Soenneker.Css.Minify
Registration
using Soenneker.Css.Minify.Abstract;
using Soenneker.Css.Minify.Registrars;
services.AddCssMinifierAsSingleton();
ICssMinifier minifier = serviceProvider.GetRequiredService<ICssMinifier>();
AddCssMinifierAsScoped() is also available. Both methods register matching lifetimes for IEsbuildUtil and IFileUtil.
Minify CSS text
const string css = """
/* navigation */
.nav .item001 {
margin: 0px 0.50rem;
color: #001122;
width: calc(100% - 1rem);
}
""";
string result = await minifier.Minify(css, cancellationToken);
// Returns the CSS minified by esbuild.
Text minification is asynchronous and accepts a cancellation token. Null, empty, and whitespace input returns an empty string. Span callers should convert their input to a string before calling.
Nonempty input uses esbuild's CSS loader with minification enabled, without bundling or resolving imports. Output follows esbuild defaults, including legal-comment preservation and a trailing newline. Browser targets are not configured, so output assumes modern CSS support.
Minify a file
await minifier.MinifyFile(
inputPath: "wwwroot/css/site.css",
outputPath: "wwwroot/css/site.min.css",
cancellationToken);
The input file is read completely, minified in memory, and written to the output path through IFileUtil. Existing output is replaced according to that utility's write behavior. File errors and cancellation propagate to the caller.
Scope and validation
The esbuild utility manages its Node/npm installation and checks npm for the latest esbuild release on each operation. Nonempty minification therefore requires network access, a writable installation directory, and permission to launch processes. This is intended for asset/build pipelines; cache generated output rather than minifying on every web request.
Esbuild failures and cancellation propagate to the caller. Minification can rewrite CSS syntax and colors, and output may change as esbuild updates.
Minification is not sanitization. Do not treat arbitrary CSS as safe merely because it passed through this library.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net11.0 is compatible. |
-
net11.0
- Soenneker.Esbuild.Util (>= 11.0.55)
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 |
|---|---|---|
| 11.0.203 | 0 | 11/15/2026 |
| 11.0.202 | 84 | 11/12/2026 |
| 11.0.201 | 77 | 11/11/2026 |
| 11.0.200 | 63 | 11/11/2026 |
| 11.0.199 | 85 | 11/11/2026 |
| 11.0.197 | 79 | 11/11/2026 |
| 11.0.196 | 77 | 11/11/2026 |
| 11.0.195 | 66 | 11/11/2026 |
| 11.0.194 | 116 | 11/10/2026 |
| 11.0.193 | 169 | 11/3/2026 |
| 11.0.192 | 100 | 11/3/2026 |
| 11.0.191 | 105 | 11/3/2026 |
| 11.0.190 | 89 | 11/3/2026 |
| 11.0.189 | 97 | 11/3/2026 |
| 11.0.188 | 101 | 11/3/2026 |
| 11.0.187 | 105 | 11/3/2026 |
| 11.0.186 | 111 | 11/3/2026 |
| 11.0.185 | 96 | 11/2/2026 |
| 11.0.184 | 109 | 11/2/2026 |
| 11.0.183 | 98 | 11/2/2026 |
Update dependency Soenneker.Esbuild.Util to 11.0.55 (#392)