Properly cache subscription on the client


Hi guys!

So … I have a pretty big subscription in my app. It does not have to be reactive (of course it would be nice if it still was), as the data behind it usually only changes approx once per day.
What I would like to do is basically only subscribe once in one of my “parent components” (my frontend is React) and then only use it on the client.

As the data will be quite big, I do not want to cancel the subscription on route change, but keep it in memory/cache all the time. My question is: What is the best way to approach this?

Some ideas:

  • Subscribe in my <App/> component. Problem: This component also re-renders from time to time - Subscription will be lost and refetched again and again right? Is there a way to not cancel it?
  • Use a method to receive the data and then use something like zangodb on the client to work with the data.
  • no more ideas :smiley:

What are your ideas on this?

best, P


There are a bunch of ways to solve this and the 2 that you mentioned would actually work fine. As for the first option you wouldn’t have to worry about re-fetching because Meteor is smart enough to reuse the existing subscription.

Additional suggestions just in case.

  1. Subscribe outside of your UI code completely, possibly inside a Meteor.startup()

  2. Use a null publication and avoid a subscribe altogether. <-- This would actually be my preferred route for data that you always need. This is especially useful because fast-render packages gather null publications to be sent to the client with the HTML payload so they are ready on first render.