Fred Fred - 17 days ago 8
AngularJS Question

Business Logic in the javacript

currently I am working in a project, i am just following what my old co-employee was doing, they're using ASP.NET (c#) and angularjs. I was surprised that all their business logic was computed in the javascript part and just use the c# part to communicate the database, fyi, we are using stored procedures all the time. Is this really a good way of structuring the system?. I want to open up this that perhaps its not a good practice, but I don't have any strong reason, since I came from PHP world.

Answer

Putting business logic in JavaScript should be avoided for multiple reasons:

  1. Design: Mostly, the business layer should be at the server and only UI layer i.e. HTML/JavaScript should be at the disposal of the client-side.
  2. Security: The more knowledge is available in the public domain, the more chance of a threat to the application.
  3. Maintenance: Business objects can be reused more effectively than embedding the business logic in JavaScript. Often I have seen each .aspx page has its own set of JavaScript files. This may not always hold true.