Skip to content

Discussion: Guidance on using the new JavaScript Initializers in Blazor/.Net 6 #37078

@user72356

Description

@user72356

According to https://docs.microsoft.com/en-us/aspnet/core/blazor/javascript-interoperability/?view=aspnetcore-6.0#javascript-initializers, "Use of JS initializers often removes the need to manually add script references when using Razor class libraries (RCLs)."

Right now when I publish a RCL that uses JS interop, I need the user to reference my .js files in his own code, in some manner, as described in https://docs.microsoft.com/en-us/aspnet/core/blazor/javascript-interoperability/?view=aspnetcore-6.0#location-of-javascipt

I fail to grasp how beforeStart(options) and afterStarted(blazor) could be used to load an external .js file. I see that Blazor can be started manually and a script injected according to https://docs.microsoft.com/en-us/aspnet/core/blazor/javascript-interoperability/?view=aspnetcore-6.0#inject-a-script-after-blazor-starts, but that relies on the user changing autostart to false, and I'm not sure where to grab the blazor object from in the beforeStart(options) JS callback. I didn't find documentation of the options and blazor JS objects.

Can anyone shed a little light on that? All I'm trying to do is to automagically load external .js files from an RCL with no user intervention besides loading the RCL NuGet.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocsThis issue tracks updating documentationarea-blazorIncludes: Blazor, Razor Components

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions