0

i tried to use JavaScript in blazor static server side rendering

first try to use a section outlet in layout and a section content in page , but a problem occurred

let's say i have a home page , and have a homepage.js file , i reference it as following

 <SectionContent SectionName="pagescripts">
    <script src="./homepage.js" ></script>

</SectionContent> 

my code run very well , but when navigate to another page let's call it weather and come back to home page , my script not worked anymore !

try to solve my problem and google it , then find bellow link
https://learn.microsoft.com/en-us/aspnet/core/blazor/javascript-interoperability/static-server-rendering?view=aspnetcore-8.0

but when read it , it's seem like it's incomplete , like where to add wwwroot/BlazorPageScript.lib.module.js
or what it is page-script , where it is defined or how define it

<page-script src="@Src"></page-script>

and what mean we add a query string each time to js file on bellow code

<PageScript Src="./Components/Pages/PageWithScript.razor.js?counter" />

expected to easily use javascript like usual add a js file on a page , like using in asp.net core razor pages , if js changed , send a request to get new file , otherwise use the cached file , we use asp-append-version= true on asp.net core razor pages , i dont know how do it in blazor

1 Answer 1

1

Use this package and onUpdate function:

https://github.com/MackinnonBuck/blazor-page-script

Sign up to request clarification or add additional context in comments.

1 Comment

Although it was not answered directly, but using the package sent, my problem was solved to a large extent

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.