Advertisement
Advanced ASP.NET Core, Blazor Integration with ASP.NET Core

How would you configure and use output caching or response caching for the static, non-interactive portions of a Blazor application?

Short answer

Static Server-Side Rendered (SSR) Blazor pages/components (using the default, non-interactive render mode) produce standard HTML responses that flow through the same ASP.NET Core middleware pipeline as any other response, meaning UseOutputCache() and [OutputCache]…

Save ASP.NET Core mock interview
Advertisement
AModel answer
Static Server-Side Rendered (SSR) Blazor pages/components (using the default, non-interactive render mode) produce standard HTML responses that flow through the same ASP.NET Core middleware pipeline as any other response, meaning UseOutputCache() and [OutputCache] attribute-equivalent configuration (via CacheOutput() on route registration) work identically for caching Blazor SSR output as they would for an MVC view -- though genuinely interactive (Server/WebAssembly render mode) components aren't cacheable in the same way since their content depends on live, per-user interactive state.
builder.Services.AddOutputCache();

app.UseOutputCache();
app.MapRazorComponents<App>()
    .AddInteractiveServerRenderMode()
    .CacheOutput(policy => policy.Expire(TimeSpan.FromMinutes(5)));  // applies to static SSR pages
Real-world example
A content-heavy Blazor site caches its static SSR marketing pages for 5 minutes using output caching, dramatically reducing server load for high-traffic, rarely-changing pages, while leaving genuinely interactive dashboard components uncached since their content is inherently dynamic per-user.
Likely follow-ups
  • Why can't fully interactive Blazor components be cached the same way as static SSR output?
  • How does this caching strategy interact with per-component render mode mixing in .NET 8+?
Related topics