Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

848
Views
Blazor WASM Script tags should not be placed inside components because they cannot be updated dynamically. Move the script tag to the index.html file

I'm developing a .Net 6 Blazor Wasm app. I need to place <script type="application/ld+json"> inside each landing page component for SEO benefits.

I'm already making use of <HeadContent> to add other <meta> and <link> tags. So I decided to use the same component for this purpose.

However when I place the <script> tag inside <HeadContent>, I'm getting the compilation error as follows,

Script tags should not be placed inside components because they cannot be updated dynamically. To fix this, move the script tag to the 'index.html' file or another static location.

To workaround this issue, I added my script tag as string text inside <HeadContent> as shown below,

@page "/"
@inject NavigationManager NavigationManager

<HeadContent>
   @($@"<script type=""application/ld+json"">
        {{
            ""@context"": ""https://schema.org"",
            ""@type"": ""WebSite"",
            ""publisher"": {{
                ""@type"": ""Organization"",
                ""name"": ""Page Name"",
                ""url"": ""{NavigationManager.BaseUri}"",
                ""logo"": {{
                    ""@type"": ""ImageObject"",
                    ""url"": ""{NavigationManager.BaseUri}favicon.ico"",
                    ""width"": 16,
                    ""height"": 16
                }}
            }},
            ""url"": ""{NavigationManager.BaseUri}"",
            ""mainEntityOfPage"": {{
                ""@type"": ""WebPage"",
                ""@id"": ""{NavigationManager.BaseUri}""
            }},
            ""description"": ""some good description about the page""
        }}
    </script>")
</HeadContent>

But this renders the script as text inside head tag in browser as shown in below screenshot:

Rendered HeadContent

Will this affect SEO benefits or is there any better way to handle this? Please assist.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

If you are sure you know what you are doing and want to use a script tag - and will test thoroughly - you can override the warning like this

<script suppress-error="BL9992">...</script>

In this case, as your script contains json it may be ok

over 4 years ago · Santiago Trujillo Report

0

You are rendering a string not markup.

@(new MarkupString($@"<script type=""application/ld+json"">
        {{
            ""@context"": ""https://schema.org"",
            ""@type"": ""WebSite"",
            ""publisher"": {{
                ""@type"": ""Organization"",
                ""name"": ""Page Name"",
                ""url"": ""{NavigationManager.BaseUri}"",
                ""logo"": {{
                    ""@type"": ""ImageObject"",
                    ""url"": ""{NavigationManager.BaseUri}favicon.ico"",
                    ""width"": 16,
                    ""height"": 16
                }}
            }},
            ""url"": ""{NavigationManager.BaseUri}"",
            ""mainEntityOfPage"": {{
                ""@type"": ""WebPage"",
                ""@id"": ""{NavigationManager.BaseUri}""
            }},
            ""description"": ""some good description about the page""
        }}
    </script>"))
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!