0
votes

I have a multi-page application with several routes. The subscription for each route is implemented using "waitOn", and it works fine.

I noticed that when I navigate to different pages, the subscription of the previous route is dropped. So far, no problem.

I implemented a "waitOn" call on the Router.configure level, so that a particular subscription is available from all pages.

My question is: Does Iron Router make a new call for that subscription each time I switch pages? I worry this would waste server resources.

Thank you.

2

2 Answers

0
votes

Yes, when you switch a page the previous subscription is dropped, later when you browse back to that page Meteor resubscribes.

There is a community package in atmosphere that caches subscriptions: https://github.com/meteorhacks/subs-manager

0
votes

So to expand on that, I did more testing and it looks like even though Iron Router tries to run the same Router.configure subscription every time a page is switched, the server only appeared to run the publish function once (I placed a console.log inside the publish function to see).

I think this is explained by their docs:

If you call Meteor.subscribe within a reactive computation, for example using Tracker.autorun, the subscription will automatically be cancelled when the computation is invalidated or stopped; it's not necessary to call stop on subscriptions made from inside autorun. However, if the next iteration of your run function subscribes to the same record set (same name and parameters), Meteor is smart enough to skip a wasteful unsubscribe/resubscribe.