AdrienTorris / awesome-blazor

Resources for Blazor, a .NET web framework using C#/Razor and HTML that runs in the browser with WebAssembly.
Creative Commons Zero v1.0 Universal
8.79k stars 973 forks source link

Blazor app as a Web Worker only #248

Closed cordasfilip closed 2 years ago

cordasfilip commented 4 years ago

Dose anyone know is it possible to compile a blazor web worker only app? I honestly don't know where to ask his question, it's way too undefined for Stack Overflow so can anyone help me on this. I can see a lot of potential in running a only some c# code as a simple function in an existing web app rather than having to do a total rewrite of an existing app that already uses some javascript framework(React, Angular Vue...). From what I can tell the only way to do it is run a hidden I frame with window events to send messages to it but this sounds like an overkill. Making it a simple web worker(https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers) sounds like a much better idea.

chrissainty commented 4 years ago

I'm not sure if Blazor is the right choice here. Blazor is for building UI's, it's a UI framework. If you're not using it for that then it's not worth it. You would have to deal with downloading the whole .NET runtime just to fire a small piece of code which would be far more efficient written in JavaScript.

cordasfilip commented 4 years ago

@chrissainty Well sort of. I am not talking about 'small' code exactly but reusing exiting c# to be executed on the client. Let's say I wanted to use a parser I written in superpower on my app on an existing site in a search box. Or using an actor model like akka with actors running on the client. Having to rewrite a whole app just to do this sounds too work intense. For example Orleans has a nice server side sample https://github.com/dotnet/orleans/blob/master/Samples/2.3/Blazor/Sample.ServerSide/Pages/Todo.razor for real time updates but it doesn't show client stuff. But I can see the benefits of this sort of logic and state management being done on existing applications. This is not intended for apps that need a short start up time but a lob app.

chrissainty commented 4 years ago

You could replace certain pages of your app with Blazor pages. As it's a line of business application, having the initial download of the .NET runtime won't be a big issue. But you're going to to be loading a whole new app so if you need to persist state across your existing app and the Blazor app you will need to work that out.

AdrienTorris commented 2 years ago

I close this issue, if it's still a question for you consider ask the question here: https://docs.microsoft.com/en-us/answers/topics/364821/dotnet-aspnet-core-blazor.html