Loading episodes…
0:00 0:00

Check if Blazor App is Running On WebAssembly Using IJSInProcessRuntime

00:00
BACK TO HOME

Check if Blazor App is Running On WebAssembly Using IJSInProcessRuntime

10xTeam August 29, 2020 1 min read

Blazor apps can run both on server-side or client-side via webassembly. In this short example, we’ll see how to check if your app is runnning with server-side Blazor or webassembly.

The trick is to use the IJSInProcessRuntime interface. This is example which displays if the app is running inside a webassembly environment or in the server when clicking on a button.

@page "/runtime"

<button @onclick="@onClick"> Check Runtime </button>

@code {

    [Inject]
    protected IJSRuntime ijsRuntime { get; set; }

    private void onClick()
    {
        var isWebAssembly = this.ijsRuntime is IJSInProcessRuntime;

        if(isWebAssembly){
           Console.WriteLine("The app is running on WebAssembly");
        }
        else{
            Console.WriteLine("The app is running on sever-side");
        }

    }
}

Join the 10xdev Community

Subscribe and get 8+ free PDFs that contain detailed roadmaps with recommended learning periods for each programming language or field, along with links to free resources such as books, YouTube tutorials, and courses with certificates.

Audio Interrupted

We lost the audio stream. Retry with shorter sentences?