Skip to content

Add to the Documentation on Importing Javascript modules that the script file is automatically downloaded when the Page is Rendered #34414

@gregoryagu

Description

@gregoryagu

Description

There is a feature that is not described in the docs on Javascript interop. This feature is that this code will automatically download the js file when the page is navigated to. In other words, there is no need to add a script tag to the App.razor file. In fact, if you do add it, it will not download successfully. To see this issue, uncomment the script tag in App.razor to force the browser to attempt to download it.

module = await JS.InvokeAsync<IJSObjectReference>("import",
    "./Components/Pages/CallDotnet1.razor.js");

Here is a simple Repro: https://github.com/gregoryagu/CallDotNetFromJs/

I would suggest adding text to describe this feature so that the user does not try to manually add the script tag, and also it is a really cool feature.

Page URL

https://learn.microsoft.com/en-us/aspnet/core/blazor/javascript-interoperability/location-of-javascript?view=aspnetcore-9.0#load-a-script-from-an-external-javascript-file-js-collocated-with-a-component

Content source URL

https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/blazor/javascript-interoperability/location-of-javascript.md

Document ID

af240267-89c0-f192-7807-cf426001ad8d

Article author

@guardrex

Related Issues

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions