Search code examples
webscriptingsynchronizationblazortiming

Script files in index.html loads before the content


I am moving an existing html portfolio hosted in githubpages to Blazor, but when the index.html loads it doesn't load the script libraries on time, but it loads them before the content is shown.

Do you know if there is Scripts section as in ASP.NET MVC, or do you know how I can tell to Blazor to loads the content synchonously?

Example: The working website is here http://tanyo.takerman.net. The non working is here http://tanyo-blazor.takerman.net The second one don't loads the scripts on time, but too late after the html is loaded.


Solution

  • Disclaimer: You are using a LOT of JS. Blazor keeps an internal render tree - a bit like a shadow dom, but not exactly that. If your JS changes the dom inside the <app> tag, you can expect errors as Blazor won't know about those changes.

    To delay Blazor startup (I think that is what you are trying to do) until after your scripts have loaded, you can turn off autostart.

    <script autostart="false" src="_framework/blazor.webassembly.js"></script>
    

    And then in some other script that runs at the right time (I don't know how you are going to know what is the right time), you can call window.Blazor.start(); to start the Blazor app.