Meteor methods should be defined on both client and server accoding to the documentarion



On the example todos app, methods are defined only on the server? why?



They can be defined on the server or the client and the server. The reason for defining them on the client is for optimistic UI (latency compensation). The method will run on the client with whatever data is available in the client side document cache (minimongo), then the method will really run on the server using the data in the whole database. Any conflicts between the results are then automatically resolved (one of the beauties of Meteor).

If your method involves updating/removing/inserting documents that aren’t published to the client, there’s not much point running the method on the client (with all that unnecessary code getting downloaded to the client, but giving no value to the user).

I’d say that in something like the todos example, the method should arguably be defined on both client and server, as you’d want “instant” responses to user actions. If they’re only defined on the server, the user has to wait for the client-server-client round trip to see the UI update.


For security reasons I define methods under \server by default, unless the code needs to also be available to run on both client and server.

“Optimistic UI” is just a gimmick to me.