BetterCache.Extensions
2026.1.1
dotnet add package BetterCache.Extensions --version 2026.1.1
NuGet\Install-Package BetterCache.Extensions -Version 2026.1.1
<PackageReference Include="BetterCache.Extensions" Version="2026.1.1" />
<PackageVersion Include="BetterCache.Extensions" Version="2026.1.1" />
<PackageReference Include="BetterCache.Extensions" />
paket add BetterCache.Extensions --version 2026.1.1
#r "nuget: BetterCache.Extensions, 2026.1.1"
#:package BetterCache.Extensions@2026.1.1
#addin nuget:?package=BetterCache.Extensions&version=2026.1.1
#tool nuget:?package=BetterCache.Extensions&version=2026.1.1
BetterCache
Bring .NET 10 Blazor cache optimizations to .NET 9 projects via a single NuGet package: fingerprinting, pre-compression (Brotli/Gzip), preload hints, and aggressive immutable HTTP cache headers.
What it does
- Immutable cache headers for fingerprinted
_framework/*assets (1-yearmax-age, immutable), withmust-revalidateonblazor.boot.json. - Pre-compressed static file serving — rewrites requests to
.br/.gzsiblings when the client supports the encoding. - MSBuild
CompressAssetstask — produces.br/.gzsiblings at build time usingSystem.IO.Compression.BrotliStream(no externalbrotli.exedependency). No-op on assets the Blazor WebAssembly SDK already compresses; covers Blazor Server apps and custom static assets. - Preload hints — optional inline script that fetches
blazor.boot.jsonclient-side and emits<link rel="preload">tags with the real fingerprinted URLs, avoiding the "preloaded but not used" warning.
Install
Published to nuget.org and GitHub Packages.
nuget.org (default)
dotnet add package BetterCache.Extensions
GitHub Packages (mirror)
dotnet nuget add source \
--username <your-github-user> \
--password <YOUR_GITHUB_PAT> \
--store-password-in-clear-text \
--name github \
"https://nuget.pkg.github.com/massimopaganigh/index.json"
dotnet add package BetterCache.Extensions --source github
The PAT needs the read:packages scope (and write:packages to publish).
MSBuild props/targets auto-import via the NuGet build/ convention.
Publish
Tagged pushes (v*) trigger .github/workflows/publish.yml, which packs BetterCache.Extensions and pushes to both feeds:
- nuget.org via
secrets.NUGET_API_KEY(repo secret — create from https://www.nuget.org/account/apikeys) - GitHub Packages via
secrets.GITHUB_TOKEN
Manual publish:
dotnet pack BetterCache/BetterCache.Extensions/BetterCache.Extensions.csproj -c Release -o ./artifacts
dotnet nuget push "./artifacts/*.nupkg" --source https://api.nuget.org/v3/index.json --api-key <NUGET_API_KEY> --skip-duplicate
dotnet nuget push "./artifacts/*.nupkg" --source github --skip-duplicate
Usage
Program.cs:
using BetterCache;
builder.Services.AddBetterCache(options =>
{
options.EnablePreloadHints = true;
options.PreloadFrameworkFromBootManifest = true;
});
var app = builder.Build();
app.UseBetterCache(); // before MapStaticAssets
app.MapStaticAssets();
Head of your root layout:
@using BetterCache
<BetterCachePreload />
Options (BetterCacheOptions)
| Property | Default | Purpose |
|---|---|---|
ImmutableMaxAgeSeconds |
31536000 |
max-age for fingerprinted framework assets. |
FrameworkPathSegment |
/_framework/ |
Path segment that identifies framework assets. |
BootManifestFileName |
blazor.boot.json |
Always revalidated. |
ServePrecompressedAssets |
true |
Serve .br / .gz siblings. |
EnablePreloadHints |
false |
Emit <link rel="preload"> tags. |
PreloadAssets |
[] |
Static preload entries (use only for fingerprint-stable URLs). |
PreloadFrameworkFromBootManifest |
false |
Inject inline script to preload fingerprinted framework assets. |
BootManifestPath |
_framework/blazor.boot.json |
Relative to base href. |
Projects
BetterCache.Extensions(net9.0) — runtime library: middleware, extensions,BetterCachePreloadcomponent,build/*.props|targets.BetterCache.Extensions.Tasks(net8.0) — MSBuildCompressAssetstask assembly.BetterCache— sample Blazor Web App consumer.BetterCache.Client— sample Blazor WebAssembly client.
Notes
- Do not preload
_framework/dotnet.runtime.jsor_framework/dotnet.native.wasmwith static URLs in .NET 9 — they are fingerprinted (dotnet.runtime.<hash>.js) and the URL will not match the real fetch. UsePreloadFrameworkFromBootManifestinstead. - ProjectReference consumers must explicitly
<Import>thebuild/*.props|targetsfiles — auto-import only applies via NuGet. PackageIdisBetterCache.Extensions, notBetterCache, to avoid a NuGet restore collision with the sample project name.
License
MIT — see LICENSE.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net9.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.