Question

Users frequently open multiple tabs to my meteor app. Is there a way to get those tabs to share the same connection (state on the server) so that there isn't multiple redundant connections. I'm thinking about coming up with a package to do this myself, I'm wondering if anyone has given any thought to this. It should help with performance.

Was it helpful?

Solution 2

You should be able to use HTML5 local storage for this. This library does just that:

https://github.com/diy/intercom.js

OTHER TIPS

It is possible to share client-side data through localStorage (consider it a browser database). It is also possible to share server-side data, commonly through database (MongoDB in case of meteor). Network connection (instead of collection) is shared across tab automatically by the browser.

If you mean sharing collection (instead of connection), you don't need to do anything special to share them between tabs (clients). Clients observing the same collection will see same data.

However, the convenience offered by Meteor has its cost. One of it is that each client has its own partial collection copy, thus it can use/waste lots of memory.

This is implementation details, and just like how JavaScript use/waste more memory and cpu then native code in exchange for convenience, there is not much you can do about it, at least not easily.

Update: As Harry noted, for real DDP connection 'sharing', it is possible to detect and disconnect new tabs and use localStorage to sync data from first tab, so that there is only one active connection. However IMHO it would be quite a heroic feat.

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