What are JavaScript Initializers (beforeStart, afterStarted), and what are they used for?
Last updated
JS initializers are exports in
{PackageId}.lib.module.jsthat Blazor auto-discovers and runs around startup.beforeStartruns before the runtime boots (customize loading, options, early scripts/CSS).afterStartedruns once interop is ready (init JS libraries, global handlers).Main use: Razor Class Libraries or NuGet packages needing setup without editing the host page.
- https://learn.microsoft.com/en-us/aspnet/core/blazor/fundamentals/startup?view=aspnetcore-10.0
- https://blazor-university.com/javascript-interop/javascript-boot-process/
- https://github.com/dotnet/aspnetcore/issues/37078
- https://www.thinktecture.com/en/blazor/understanding-and-controlling-the-blazor-webassembly-startup-process/
- https://learn.microsoft.com/en-us/aspnet/core/blazor/components/js-spa-frameworks?view=aspnetcore-10.0