All-js or initial markup by the framework

Ever since I've started mvc development my experience is almost 80% jQuery, only 20% C#.

Now I am begginning to use Knockout.js to enable myself to better control view on the page.

The question I am now facing is: should I be feeding the browser the "sceleton markup page" and load all data via ajax call, which in turn populates a js viewmodel object and therefore the view, or should I initially populate data via a partial view, and use js page data management for subsequent client experience?

Right now I am doing the latter, but this requires me to write two data retrieval/display logic - one in js, one in mvc razor view.

I am not planning to support browsers with js disabled, so maybe I should do everything via js knockout view model initialization?


There are many additional variables.

  1. How many request per second should your app handle in future? If many, then with full page generation maybe you can cache resulting web page, decreasing load on server.
  2. What kind of clients do you have? If they are slow (like low cost mobile phones), then generating full HTML on client can be slow.
  3. Do your clients appreciate fast response over slow network? With full server page generation you can achieve smaller number of requests and faster response.

On the opposite side, if this is an internal department level business app with good network, low number of requests and good client computers, then you can surely go with minimal initial page and populating everything with AJAX. Also, as Arbiter pointed out, JSON can be smaller in size than HTML, so if you have a big amount of data then you can save on network via JSON.

There is also a middle third way. You can generate JSON data and embed them directly in the webpage (like <script>CallMyJSGenerateMethod({generatedJSON: "goes here"})</script>). This way you'd have only one (JavaScript) procedure for HTML generation, small number of requests (with even lower amount of data) and ability to cache web page. Still, you'd have to have a good clients, so point 2 still stands.

This is more of an opinion, but in my estimation, its the most oft asked question I get regarding building web apps: do I build the pages with HTML/MVC on the server or do I use all JS? There is no clear right answer here that fits all scenarios. Both are great choices. Dmitry's points are all valid, too.

Other things to consider are whether you need to stick with ASP.NET on the server or if other server tech will be used (PHP?). What skills does your dev team have? Will the pages you are creating change a lot on the client, or are they relatively static?

I personally lean towards the client space instead of server side generation, but its mostly a preference.

Need Your Help

Android app force closes - setOnClickListener [simple app] [beginner]

java android class onclicklistener logcat

Program functions as normal on start up. As soon as button is clicked, app force closes and the log cat (at bottom) is shown.

Why does DomDocument prepend this character (Â) when I use the degree (°) symbol?

php encoding utf-8

I have a section of code that parses some content from a webpage and I can't figure out why it's inserting the  in front of the degree symbol.