When I remove the" /> When I remove the" /> When I remove the"/>

Why is blazor.server.js blocking my other js files?

463 Views Asked by At

I have Blazor Server Web App Project that contains this default javascript link:

<script src="_framework/blazor.server.js"></script>

When I remove the link, my other js files load correctly, but if I add it back then they do not load. It does not matter if I add blazor.server.js before or after my js links.

HOW TO RECREATE MY SCENARIO:

  1. Create default Blazor Server Web App
  2. Add a new demo.js file to wwwroot and enter this js code:
$(document).ready(function () {
    
    $("#clickme").on("click", function () {
        alert("Handler for the 'Click Me' button is called.");
    });
});
  1. Add demo.js to _Host.cshtml like this: <script src="~/demo.js"></script>

  2. Create a button in /Index or /Counter and add: id="clickme"

  3. Make sure that <script src="_framework/blazor.server.js"></script> is present in _Host.cshtml

Buid and Run.

Result 01:

  1. The Blazor Server Web App will run but when you click the button, js code is not called.

Now, remove <script src="_framework/blazor.server.js"></script>, build and run.

Result 02:

  1. The Blazor Server Web App will run and when you click the button, js code is called correctly.

I want to include <script src="_framework/blazor.server.js"></script> and other js files and make them work.

What could be the problem?

I am using:

  1. Visual Studio IDE 2022
  2. Blazor Server Web App
  3. .NET 7
0

There are 0 best solutions below