0

Looking at this question:

SO question

The accepted answer by Darin Dimitrov looks appealing (.NET 4.5 version). I am just wondering how this compares performance wise with client side solutions (e.g. using knockout/angular/jquery) to assemble the HTML given some JSON from the web api endpoint. Did someone ever do some perfromance tests on this. What are the pros and cons of the 'client side solution' vs the 'razor server side' solution?

Community
  • 1
  • 1
cs0815
  • 16,751
  • 45
  • 136
  • 299
  • Your MVC app and Web APIs are likely in the same solution, or probably close to each other, which would be faster than a browser making the request from anywhere in the world. If you're really concerned about performance, you should probably be looking at WCF and use TCP over HTTP. – Mister Epic May 29 '14 at 11:36
  • That both are close or in the same solution does probably not reflect the hosting situation does it? Or am I missing something? – cs0815 May 29 '14 at 11:44

1 Answers1

2

You should have to define performance.

However there is a very big difference between the two options:

  • if you do it client-side (with ko/ng/jQuery) the server only executes the API controller action and returns the formatted data.
  • if you do it server side, apart from execution the API action, the server has to execute the MVC controller action, so, undoubtedly, the server does more work.

The only conclusion is that the server has less work to do in the first case. And, usually, the network traffic is reduced (a JSON object is usually lighter than a rendered partial view).

If we're speaking about the user experience, in general client side technologies (jQuery, ko, ng) offer a much better user experience becasue the page is much more responsive: it's easy to show/hide elements, set the focus, make trivial calculations, remote validations... And if we use modern libraries, we can go further on improving the interface resposiveness. For example breeze.js allows to cache data in the client side to avoid making extra ajax calls to the server, giving a much more responsive experience, specially if you anticipate what data can be needed and cached it before hand. You could even persist data in HTML5 storage, so that it's available for other sessions.

Then, from the user viewpoint, I think it's much better the second option. And the server has less work to do, which can make it also more resposive in high-traffic sites.

Even so, I don't know what is "more performant" or even what it is "to be performant".

Whatever it is, using client side technologies is a much better option. But it takes some time to master the associated technologies.

JotaBe
  • 38,030
  • 8
  • 98
  • 117