firebasegoogle-cloud-firestoreoffline-caching

Firebase offline persistence - Upfront caching possible?


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!


Solution

  • 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.