Topic: Using client-side javascript or not ?

I have a quite complex form with about 20 fields that are related and computed to update page with RJS. Some fields have relations to 2-3 other fields, others are just dependent from another field.

At the moment I am using a observe_form to send the parameters back to the server, perform some calculation and update the the page with RJS, which works perfectly well.

But to me it doesn't look like I really had to send all fields every time the form changes (and thats the behavior of observe_form) as there are quite a lot fields generating (unnecessary) traffic on the internal net.
For my understanding, ajax should only be used to get 'new' information from the server...

Advantages of sending all parameters back to the server is it allow to use ruby instead of js and the client doesn't see logic and is not able to manipulate it.

What do you think is more adequate, using client-side js or stick with ajax ?

Re: Using client-side javascript or not ?

From a performance standpoint you should use AJAX only when necessary. If you can mimize the traffic going back and forth, or better yet skip the call to the server completely, then that will result in better performance on the client side and less bandwidth used.

But Rails makes AJAX so easy that the alternative can be much more difficult with lots of custom javascripts. To me it's only worth changing if you can remove the call to the server completely and do everything client side.

Railscasts - Free Ruby on Rails Screencasts

Re: Using client-side javascript or not ?

ryanb wrote:

From a performance standpoint you should use AJAX only when necessary.

As a rule of thumb:
Do you agree that necessary means request information that is _only_ available on the server and not manipulating data on a document where all information is available ?

What about a security standpoint ? Some other drawbacks when using js on the client side besides adding complexity and logic into js ?

Even though js would speed up the application and make it easier to scale I still hesitate a bit to put the logic into js...

Re: Using client-side javascript or not ?

boemitsu wrote:

Do you agree that necessary means request information that is _only_ available on the server and not manipulating data on a document where all information is available ?

For the most part, yes. However, this sometimes makes it more inconvenient for the developer.

boemitsu wrote:

What about a security standpoint ?

I can only see security being an issue if the server relies on the javascript behaving a certain way. Take form validation for example. It is more efficient (performance-wise) to validate the form input completely on the client side through javascript, but there needs to be another validation on the server side as well since the client can bypass the javascript validation. This results in duplication which can be a big inconvenience for the developer. So it's a trade off.

boemitsu wrote:

Some other drawbacks when using js on the client side besides adding complexity and logic into js ?

Even though js would speed up the application and make it easier to scale I still hesitate a bit to put the logic into js...

If the logic is very complex, I recommend doing whatever is easiest for you. Keep it on the server side and monitor the traffic to this. Try to estimate the benefits of doing it all client side and see if it's worth it.

Railscasts - Free Ruby on Rails Screencasts