I'm working on a Firebase web application using the Cloud Firestore database. Currently I'm experimenting with the offline persistence which is working as expected so far. The only downside I encountered so far is that data is cached only if I have already fetched it (which makes sense).
I'd like to make some pages / data in my application accessible offline. This would only work if the user navigates to those pages before going offline.
Is there any technique to add data to the Firebase cache? Something like "make this and that collection / query available offline"? This might be called upfront caching.
Thank you in advance for any hints!
CodePudding user response:
There is no official way to do this. But, there is a hack to achieve upfront caching. Simply read the needed data in your collection on the initial app open or when the app is idle.
Caution: This may increase your firestore read count!!
But surely this will work.
CodePudding user response:
This used to be impossible (as Soorya answered), but has become possible with the introduction of Firestore content bundles. With these you can create a bundle (for example as part of your release process), include that in your app as an included binary, and then ingest the bundle into Firestore when the app is first loaded on the user's device. In addition to the linked documentation, I also recommend checking out the solutions page on serving bundles.