What are JavaScript Initializers (beforeStart, afterStarted), and what are they used for?

Last updated 5 July 2026

  • JS initializers are exports in {PackageId}.lib.module.js that Blazor auto-discovers and runs around startup.

  • beforeStart runs before the runtime boots (customize loading, options, early scripts/CSS). afterStarted runs 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
All Blazor interview questions