Methods and Schema on `client` or `server` or both?

For Meteor 1.6.1.3

Hey everyone,

  • I’m confused, the docs say Meteor methods should be defined on both client and server side?
    Or just in Imports folder?

I understand that on client Meteor methods help with optimistic UI and send DDP message with that message name, so, do i need to Duplicate Methods on both Client and Server?

  • Also, I’ve been defining Schemas in imports/ folder. But this causes my client bundle size to increase by ~40kB. If i move all Schemas to server/. Will it help reduce bundle size? and will it still work with minimongo?

As per docs anything in imports folder will only be included if its imported somewhere.

  • So if i define a method in imports folder and call it in server/ folder, does it become server-sided?

Thanks a lot :blush:

1 Like

Welcome Mahaveer!

  • I’m confused, the docs say Meteor methods should be defined on both client and server side?
    Or just in Imports folder?

Following the folder structure recommended by the Meteor guide https://guide.meteor.com/structure.html
Methods should be defined in the api subfolder which is the only part that the Meteor app builder loads on both the client and the server
Methods should be called only from the client, i.e., an UI component written in either Blaze, React, Angular or Vue.

Using Simple schema the schemas are defined inside the methods definition see https://github.com/meteor/todos/blob/master/imports/api/todos/methods.js

Using Astronomy it’s the other way around with the methods being defined inside the schema definition see http://jagi.github.io/meteor-astronomy/#meteor-methods--220

If you thoroughly read the tutorial for your choice of UI framework, then thoroughly read the guide and also read and fully understand the associated Github repositories before coding your app, everything shall get clearer I believe.

I hope this helps.