DynamicHead.Blazor
1.0.0
dotnet add package DynamicHead.Blazor --version 1.0.0
NuGet\Install-Package DynamicHead.Blazor -Version 1.0.0
<PackageReference Include="DynamicHead.Blazor" Version="1.0.0" />
<PackageVersion Include="DynamicHead.Blazor" Version="1.0.0" />
<PackageReference Include="DynamicHead.Blazor" />
paket add DynamicHead.Blazor --version 1.0.0
#r "nuget: DynamicHead.Blazor, 1.0.0"
#:package DynamicHead.Blazor@1.0.0
#addin nuget:?package=DynamicHead.Blazor&version=1.0.0
#tool nuget:?package=DynamicHead.Blazor&version=1.0.0
π§ DynamicHead.Blazor
Dynamic, component-driven <head> management for Blazor
π Overview
DynamicHead.Blazor brings true dynamic head management to Blazor.
Unlike Blazorβs built-in <HeadOutlet> and <HeadContent>, this library allows any component to declaratively add, update, or remove <head> content β such as <title>, <meta>, or <link> tags β without overwriting others.
π‘ Why DynamicHead.Blazor?
Blazorβs built-in head management works only at the page level, and each <HeadContent> instance overwrites the previous one.
| Limitation (Blazorβs built-in) | Solved by DynamicHead.Blazor |
|---|---|
| Only page-level head content | β Any component can register head content |
Each <HeadContent> overwrites previous |
β All content merges dynamically |
| No automatic cleanup | β Automatically unregisters on dispose |
| No runtime updates | β Dynamically re-renders live |
| No parallel or nested support | β Works in any nested component |
β¨ Features
- βοΈ Works with Blazor WebAssembly and Blazor Server
- π Automatically adds and removes head elements
- π§ Updates dynamically as component content changes
- π§± Lightweight, no external dependencies
- π§ͺ Fully unit-tested (NUnit + bUnit + Moq)
π¦ Installation
Install from NuGet:
dotnet add package DynamicHead.Blazor
βοΈ Setup (WebAssembly Example)
Program.cs
using DynamicHead.Blazor;
var builder = WebAssemblyHostBuilder.CreateDefault(args);
// Register the DynamicHead service
builder.Services.AddDynamicHead();
// Mount your app and the DynamicHeadOutlet
builder.RootComponents.Add<App>("#app");
// π§ Add DynamicHeadOutlet to the document head
builder.RootComponents.Add<DynamicHeadOutlet>("head::after");
await builder.Build().RunAsync();
π‘ head::after ensures the outlet is rendered directly inside the <head> element,
just like Blazorβs built-in <HeadOutlet> β but this version dynamically merges updates.
π§ Usage
Use <DynamicHeadContent> anywhere in your app β even inside nested components:
@page "/about"
<DynamicHeadContent>
<title>About β MyApp</title>
<meta name="description" content="Learn more about MyApp." />
<link rel="stylesheet" href="about.css" />
</DynamicHeadContent>
<h1>About</h1>
β When this component renders:
- Its content is registered in the shared head service
<DynamicHeadOutlet>re-renders the document<head>- When itβs disposed (navigated away), the content is automatically removed
π§ Comparison
| Feature | Blazor <HeadContent> |
DynamicHead.Blazor |
|---|---|---|
| Nested components | β | β |
| Multiple fragments | β Overwrites | β Merges |
| Auto cleanup | β | β |
| Runtime updates | β οΈ Limited | β Full |
Works with head::after |
β | β |
π§ͺ Testing
DynamicHead.Blazor is fully covered by automated tests using:
π License
MIT Β© 2025 Simon Liebers
| 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
- Microsoft.AspNetCore.Components.Web (>= 9.0.8)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.