Why does Blazor Server have the browser call blazor.server.js multiple times?

David Thielen 2,506 Reputation points
2024-06-26T02:39:40.0366667+00:00

Hi all;

I watched a page load using F12 and blazor.server.js is loaded multiple times (see below). I understand the browser loading multiple times because of the ?id=... being different on each. But why does the Blazor code reloading the same Javascript file instead of reading it once and then referencing that loaded file?

thanks - dave

3K25UTfl[1]

Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,470 questions
{count} votes

1 answer

Sort by: Most helpful
  1. JasonPan - MSFT 4,791 Reputation points Microsoft Vendor
    2024-06-26T06:59:27.67+00:00

    Hi @David Thielen,

    It's a expected behavior for LongPolling protocol. If you don't want to use LongPolling, you can set it in your Program.cs Like below.

    app.MapBlazorHub(options =>
    {
        options.Transports = HttpTransportType.WebSockets;
    });  
    

    By default, we can use websocket protocol directly, if not works, please kindly check the websocket feature setting in azure portal .


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best Regards

    Jason

    0 comments No comments