We won't get into the technical details of those here. Instead, this tutorial will point out some practical issues.
In practical programming, there are various levels of optimization.
On the other hand, if you are developing an application that could be potentially used by hundreds of thousands of users, some of whom may be located half way around the world at fifty network hops, you should put as much the of the work in JavaScipt as possible, so the application does not have any client-server trips that are not absolutely necessary, and so that the clients are distributing as much workload as possible.
Of course, optimization trade-offs change every few years with advances in technology and hardware. It is possible that a few years later, entirely other issues may dominate optimization instead!