AMB
AMB

Reputation: 67

How to use a javascript file on a component page in blazor static server side rendering SSR

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

Upvotes: 0

Views: 493

Answers (1)

Mohammad Komaei
Mohammad Komaei

Reputation: 9676

Use this package and onUpdate function:

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

Upvotes: 1

Related Questions