Blazor batch calls to Javascript

65 views Asked by At

I´m using Blazor and I need to invoke JS functions from C#. I have read that the calls to JS are very consuming so they should be minimized and/or batched. What is exactly batching? How can I batch the calls to JS? Is it going to improve the performance of my code or it´s just losing my time?

1

There are 1 answers

1
Todd On BEST ANSWER

99.9% of the time the performance considerations are not worth worrying about.

If you truly do need to worry then you could write yourself a JavaScript function that takes, as an argument, a list of other JavaScript function calls to make and that then makes those calls. This would keep your interopped call count at 1.

The performance / code complexity trade off doesn't make sense to me, but there are more use-cases in heaven and Earth than I can imagine.

Here is a decent post proposing another batching solution implementation. The conclusion of the post, however, is that it wasn't worth it.

https://blog.zhaytam.com/2021/09/23/blazor-js-interop-batching/