A Thought on Server Side and Client Side Models

   The truth is if you want to take server side models for example in Asp.net Mvc directly to a client side mvc framework's enviroment the common approach is via ajax. What has me troubled about this approach is that in some cases we already know the information that will be passed from server side to client before the call based on the request in some cases. So why do we make clients call this ajax? It's simply because we don't have enough ways to bridge the two technologies. Now just to be clear I'm not talking about third party api's or in any extreme case where the data is so dynamic that it is dependent on the front-end. What I am talking about is in cases where the data is in within the web application and we know what is needed by the page request. In case I haven't made myself clear (probably not) here is an example of what I mean.

     I'm going to use an example from a Asp.net Mvc perspective just because that is what I'm familar with but I sure this problems exist in all web developments framework because of th different technologies that exist in server side and client side. That is all but nodejs of course, which I will explain why later. So in any given Asp.net Mvc application you have a model that is bound to to a view. Inside the controller is that view's action result which queries the database and populates the model. Which is then passed into the view, however this does not give passed to the client-side Mvc. So instead what many developers as well as myself do is create a json result to pass the model. Which is then handled by the front-end Mvc framework. Now to get an idea of the data it's simple, and it shouldn't take long but lets say it could. In that case this is a type approach is appropriate. As it would allow the data to be async and load the page faster but not be tied down by the backend (database query) but what if the call isn't to a database? What if its just a model defined in the controller or some data stored in an index always ready. I had some great experience using Solr this last couple of months and I would say that making users do this ajax call when I know it's information that always going to be there is unnecessary. It creates more chatter and looks sloppy for a page request when the data is more 75% of the page. So making this request from the controller and mapping to the front-end models important in my opinion. I see it as a waste of bandwidth if your making requests for resources that should already be populated on the page load.

     I have been playing around with AngularJs in Asp.net Mvc for awhile and the theory that I'm working on is either mixing the code which I rarely do but it would involve using razor sytnax inline with javavscript code. Or I could call the javascript file with a query url which I've never done but by doing so would I lose the ability to cache the file. If I was using NodeJs I could probably more direct access a server side model and reuse that model via client side without duplications. I would then create my call on the server side and directly populate the client side model but would it be worth the architectural change? Time wise probably not and the cases where this approach was appropriate would have to meet all the conditions. Conditions like where the data coming from a third part api, or dynamic content driven from the UI.

I don't think any of my resources really helped since it really isn't a concern most consider.
AngularJS client MVC pattern? - Stack Overflow
asp.net mvc vs angular.js model binding - Programmers Stack Exchange
Cookbook for ASP.NET MVC and Angular.js Web Apps | Wintellect
Single-Page Applications: Build Modern, Responsive Web Apps with ASP.NET

Popular posts from this blog

Installing Windows on Acer chromebook 15 cb3-532

Entity Framework: ToListAynsc & WhereAsync

CSharp Cheatsheet