Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC Razor view vs AngularJS

I am using ASP.Net MVC with Razor syntax in Views. But with little research on performance enhancements I have found that View Engines takes a time to compile razor code to HTML. So is it good idea to use AngularJS in Views over razor syntax? If this improves performance then what are the other pros and cons of it?

Thanks in advance.

like image 680
Tanmay Avatar asked Oct 26 '17 15:10

Tanmay


1 Answers

Which route will give you better performance is dependent on several factors. zambeb's answer regarding mvc.net razor views is not accurate.

mvc.net views are compiled the first time they are ever requested and thereafter only data is plugged into the pre-compiled view. This is a much less processor intensive operation than angular views being parsed and rendered.

However, angular views are rendered on the client (browser). If for some reason your server is insufficient for your needs your site will perform better if built with angular.

On the other hand if both sites are built with adequately sized servers an mvc.net will tend to have faster render times, because the browser has a less intensive job.

The exception to this is of course if you are building a site that will have many small ui changes that you wish to make with views instead of through dom manipulation or widgets, then again angular wins.

This is why when building with mvc.net it makes sense to build slightly larger and more complex views than angular, not that you must.

In the end each approach can be abused and under perform. Each approach also lends itself to a particular style of site.

These two approaches can also be combined. In mvc.net a layout page can be made to render views as html fragments. This means a front end angular developer only need worry about static views and controllers and the mvc.net developer concerns himself with models, dynamic views, and controllers on the server.

Good luck!

like image 138
N-ate Avatar answered Oct 20 '22 19:10

N-ate