0

This is very basic question so pardon me if it bored you.

I have 2 options:

a)Reduce the number of lines of code in helper and instead add more code in apex controller

b)Increase lines of code in lightning component helper.

By increase in lines of code in helper, what I mean is increase in "if else" constructs, adding 1 or 2 switch statements, and 1 or 2 additional methods. Pros in this approach is I can avoid a server call . My helper already has 10-12 methods , so is it advisable to add more code in it or make a server call?

Hence a more wider question is that should as much business logic be kept at client side as possible, or keep client side clean and leverage server for processing business logic.

3

I think this is a general "client-side"/"server-side" question, and not specific to lightning.

To answer your question: the size of your helper would affect the initial page load times, but no more. Adding more lines of code means a bigger javascript file, which implies a longer download time. Having said this, I find that lightning experience is quite heavy, so adding a few lines of code would not affect load times significantly.

Once it's loader, things will run faster if you don't make a server-side call (as there will be no network delay for the HTTP request).

Having said that, I think the most accepted best practice is to keep all your business logic server side, and use the client side just for rendering and for extra validation (to save an HTTP request round-trip).

Remember that your javascript code is visible to the user in the browser (using the browser developer tools), and that he can always modify your helper code and run his own. That is why all the business checks, validation, etc., should live in the server side also.

Personally, I would not put business logic in the client side, but I guess other developers may have other preferences.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.