Question

Ok, so I am new to Meteor and to programming as a whole kinda and I have a simple best practices kind of question.

I am using Iron Router, and have been using it to subscribe to different paths. I am trying to be as lean as possible and only subscribe to the collections I need using waitOn(). But after doing some reading this afternoon it seems as though it might be overkill.

What is the best practice for when you should subscribe to a collection?

My guess is if you have a collection you use on multiple pages load the whole collection in the beginning. Then only load things you only need every now and then through Iron Router's waitOn. Also, what is the best way to test if loading collections at the beginning is causing load time issues.

I know that there isn't a catch-all answer for this, and every project is different, but any advice would be appreciated.

Thanks

Was it helpful?

Solution

There is no single answer for this because it depends both on the amount of data you are subscribing for and on your willingness to tolerate latency when starting up and when changing routes.

waitOn is a powerful tool, but it's also perfectly reasonable to activate global subscriptions. It's important to note that iron-router typically starts and stops subscriptions as routes change. I can imagine a scenario where, depending on the requested routes, you would continually start and stop a particular subscription. That latency could have been avoided by starting the subscription outside of the router, but that would exchange route latency for startup latency.

You will need to experiment and see how these things affect your application performance in order to determine the best option. I'll caution you that because the size of the data being subscribed to is a big factor in the latency, you may find that your results change as you move from development to production.

The only suggestion I have for measuring load time is to use APM. I haven't tried it myself yet, but I have heard it can help give a great deal of insight into performance.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top