Install ASP.NET Core middleware
Install ModPageSpeed as ASP.NET Core middleware via NuGet. Same optimization pipeline, no nginx required.
ModPageSpeed runs inside your ASP.NET Core pipeline as middleware, installed as a NuGet package. Same optimization pipeline as the nginx integration — image transcoding, CSS/JS minification, critical CSS — invoked via P/Invoke to the native C/C++ library. No separate reverse proxy or sidecar is required.
Prerequisites
- .NET 8 SDK or .NET 10 SDK — dotnet.microsoft.com. The package targets
net8.0andnet10.0. - Supported platform: Linux x64 or arm64, macOS ARM64 (Apple Silicon), or Windows x64
- An ASP.NET Core application that serves HTML responses (Razor Pages, MVC, Blazor Server, or minimal APIs returning HTML)
Install the package
A single dotnet add command is enough — the meta-package pulls in the core
abstractions and all native-asset packages transitively.
dotnet add package WeAmp.PageSpeed.AspNetCore --prerelease
Three native-asset packages ship alongside the managed assemblies — one each
for linux-x64/linux-arm64, osx-arm64, and win-x64. NuGet pulls all of
them as transitive dependencies; MSBuild’s RID resolution loads only the
matching platform’s binary at publish/run time.
Add to your pipeline
Register PageSpeed services and add the middleware to your request pipeline.
using WeAmp.PageSpeed.AspNetCore;
var builder = WebApplication.CreateBuilder(args);
// Register PageSpeed services — auto-binds the "PageSpeed" section from
// IConfiguration (appsettings.json, env vars, user secrets, …).
builder.Services.AddPageSpeed();
var app = builder.Build();
// Add PageSpeed middleware — should be early in the pipeline
app.UsePageSpeed();
app.MapStaticAssets();
app.MapRazorPages();
app.Run();
Place UsePageSpeed() before any middleware that writes the response body. It
needs to intercept responses before they reach the client.
Configure via appsettings.json
Add a PageSpeed section to your appsettings.json. A minimal configuration:
{
"PageSpeed": {
"Enabled": true
}
}
That’s enough to turn on every default rewrite (critical-CSS inlining, LCP
preload, lazy loading, image dimensions, async CSS, script deferral, …). Each
rewrite is its own boolean toggle under PageSpeed:Html — see the
configuration reference for the full list.
Verify it works
Run your application and check for the X-PageSpeed response header.
dotnet run
Check the terminal output for the URL your app is listening on (e.g.
http://localhost:5123), then in another terminal:
curl -I http://localhost:<port>
Look for the X-PageSpeed header on HTML responses. It reports the cache
outcome of the request:
X-PageSpeed: MISS
or, once the cache is warm:
X-PageSpeed: HIT
If the header is present, PageSpeed is active and optimizing responses. View the HTML source to see rewritten image tags, inlined CSS, and deferred scripts.
Known limitations
- License state changes propagate to the middleware within 30 seconds (health poll interval)
Next steps
- Configuration reference — all appsettings.json options, hot reload, environment-specific config
- Licensing — Commercial subscription today; BSL 1.1 source publication on the roadmap