I created an app that does almost everything on client side. Client subscribes to all collections and keep almost whole copy of db. That makes perfect realtime app where client have instant access to all data. Data synced with the server with just background meteor’s syncing of minimongo with server’s mongo.
All works fine, except one issue. Users like to open many tabs, plus some of pages are designed to be opened in new tabs. Every time when user opens new tab, he needs to wait more than 5 seconds for all collections to be pushed to the client.
So I want to store collections to local storage (indexDB, etc) so that app can show preview data without waiting for that data to be received from the server.
I found persist-collection package (The trusted source for JavaScript packages, Meteor.js resources and tools | Atmosphere), but that package was not touched for 5 years and designed to be used offline. I don’t want to allow app to use offline, just to have some kind of cache for new tabs.
So before I started to use that package or implementing my own bicycle I wanted to ask you:
Do you have any suggestions of how to implement it, or recommendations for packages, maybe the solution is already exists and I just can’t find it?
I do this in my app, primarily for offline access but it also benefits from faster loading times.
See this thread for some info on how I do this as well as a bunch of related code (based off of ground:db). You’ll have to adapt it for your own needs though.
FWIW, you are building in offline access, at least in terms of your data store. Of course, it won’t be usable offline if you don’t have a service worker, but whatever you implement in code for the data will probably be the same as if you were going to want to have offline access.
Curious, do you have any metrics on how much it improves loading times?
In my case, it’s mostly due to network delays. I only eagerly load a small-ish amount of index data; the full records are only fetched (with Meteor methods) on demand as needed. The delay isn’t that noticeable to begin with, at least with good internet, but it’s also not instant the way it is with IndexedDB.