<?xml version="1.0" encoding="UTF-8"?>        <rss version="2.0"
             xmlns:atom="http://www.w3.org/2005/Atom"
             xmlns:dc="http://purl.org/dc/elements/1.1/"
             xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
             xmlns:admin="http://webns.net/mvcb/"
             xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
             xmlns:content="http://purl.org/rss/1.0/modules/content/">
        <channel>
            <title>
									Blazor - PureSourceCode Forum				            </title>
            <link>https://puresourcecode.com/forum/blazor/</link>
            <description>PureSourceCode Discussion Board</description>
            <language>en-US</language>
            <lastBuildDate>Tue, 10 Mar 2026 12:50:23 +0000</lastBuildDate>
            <generator>wpForo</generator>
            <ttl>60</ttl>
							                    <item>
                        <title>Add Security Headers to Blazor WebAssembly</title>
                        <link>https://puresourcecode.com/forum/blazor/add-security-headers-to-blazor-webassembly/</link>
                        <pubDate>Tue, 05 Apr 2022 12:10:14 +0000</pubDate>
                        <description><![CDATA[In this new post, I like to explain how to add security headers to Blazor WebAssembly to follow the recommendations from OWASP.]]></description>
                        <content:encoded><![CDATA[<p>In this new post, I like to explain how to add security headers to <a href="http://s981402199.websitehome.co.uk/tag/blazor-webassembly/">Blazor WebAssembly</a> to follow the recommendations from <a href="https://owasp.org/" target="_blank" rel="noreferrer noopener">OWASP</a>.</p>]]></content:encoded>
						                            <category domain="https://puresourcecode.com/forum/blazor/">Blazor</category>                        <dc:creator>Enrico</dc:creator>
                        <guid isPermaLink="true">https://puresourcecode.com/forum/blazor/add-security-headers-to-blazor-webassembly/</guid>
                    </item>
				                    <item>
                        <title>JSInterop is not add the script before OnAfterRenderAsync</title>
                        <link>https://puresourcecode.com/forum/blazor/jsinterop-is-not-add-the-script-before-onafterrenderasync/</link>
                        <pubDate>Wed, 23 Feb 2022 11:40:04 +0000</pubDate>
                        <description><![CDATA[I have a component for Blazor. I have a JSInterop that is defined like that
public class JSMarkdownInterop
{
    IJSRuntime jsRuntime;

    public JSMarkdownInterop(IJSRuntime JSRuntime...]]></description>
                        <content:encoded><![CDATA[<p>I have a component for Blazor. I have a<span> </span><code>JSInterop</code><span> </span>that is defined like that</p>
<pre contenteditable="false"><code>public class JSMarkdownInterop
{
    IJSRuntime jsRuntime;

    public JSMarkdownInterop(IJSRuntime JSRuntime)
    {
        jsRuntime = JSRuntime;

        jsRuntime.InvokeAsync&lt;IJSObjectReference&gt;("import",
            "/_content/PSC.Blazor.Components.MarkdownEditor/js/markdownEditor.js");
    }

    public async ValueTask AddJS(string targetUrl)
    {
        await jsRuntime.InvokeVoidAsync("loadJs", targetUrl);
    }
}
</code></pre>
<p>The function<span> </span><code>loadJS</code><span> </span>is in the<span> </span><code>markdownEditor.js</code>. So, in the component I added this code in the<span> </span><code>OnInitialized</code><span> </span>function</p>
<pre contenteditable="false"><code>protected JSMarkdownInterop JSModule { get; private set; }

protected override void OnInitialized()
{
    if (JSModule == null)
        JSModule = new JSMarkdownInterop(JSRuntime);

    base.OnInitialized();
}
</code></pre>
<p>then, in the<span> </span><code>OnAfterRenderAsync</code><span> </span>I want to call the<span> </span><code>AddJS</code><span> </span>function to add some scripts.</p>
<pre contenteditable="false"><code>protected override async Task OnAfterRenderAsync(bool firstRender)
{
    await base.OnAfterRenderAsync(firstRender);

    if (firstRender)
    {
        await JSModule.AddJS(easyMDEJS);
    }
}
</code></pre>
<p>I end up to have an error because apparently the fucntion<span> </span><code>loadJS</code><span> </span>was undefined.</p>
<p><a href="https://i.stack.imgur.com/o0CrR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/o0CrR.png" alt="enter image description here" /></a></p>
<p>How you can see in the above screenshot, there is the error but also the application added the script. Then, I think the application adds the script after the first render.</p>
<p>How can I delay the first render until the script is added? Or how can I add the script on time for the first render?</p>
<h1>Update</h1>
<p>I changed the<span> </span><code>JSMarkdownInterop</code><span> </span>like that</p>
<pre contenteditable="false"><code>public class JSMarkdownInterop : IAsyncDisposable
{
    private readonly Lazy&lt;Task&lt;IJSObjectReference&gt;&gt; moduleTask;

    public JSMarkdownInterop(IJSRuntime jsRuntime)
    {
        moduleTask = new(() =&gt; jsRuntime.InvokeAsync&lt;IJSObjectReference&gt;("import",
            "./_content/PSC.Blazor.Components.MarkdownEditor/js/markdownEditor.js")
            .AsTask());
    }

    public async ValueTask AddJS(string targetUrl)
    {
        var module = await moduleTask.Value;
        await module.InvokeVoidAsync("loadJs", targetUrl);
    }
}
</code></pre>
<p>but I receive the same error.</p>]]></content:encoded>
						                            <category domain="https://puresourcecode.com/forum/blazor/">Blazor</category>                        <dc:creator>Enrico</dc:creator>
                        <guid isPermaLink="true">https://puresourcecode.com/forum/blazor/jsinterop-is-not-add-the-script-before-onafterrenderasync/</guid>
                    </item>
				                    <item>
                        <title>Dynamically add JavaScript from Blazor components</title>
                        <link>https://puresourcecode.com/forum/blazor/dynamically-add-javascript-from-blazor-components/</link>
                        <pubDate>Tue, 25 Jan 2022 20:44:06 +0000</pubDate>
                        <description><![CDATA[In this new post, I show you the code to dynamically add JavaScript from a Blazor components coming from the component itself or another URL. What do you think? Have you use this code? How c...]]></description>
                        <content:encoded><![CDATA[<p>In this new post, I show you the code to dynamically add JavaScript from a Blazor components coming from the component itself or another URL. What do you think? Have you use this code? How can I improve it?</p>]]></content:encoded>
						                            <category domain="https://puresourcecode.com/forum/blazor/">Blazor</category>                        <dc:creator>Enrico</dc:creator>
                        <guid isPermaLink="true">https://puresourcecode.com/forum/blazor/dynamically-add-javascript-from-blazor-components/</guid>
                    </item>
							        </channel>
        </rss>
		