Reputation: 101
I am working on a book reading web app using React Js where the owner can make their own books and publish in the app . Since the data can be enormous so i wan't to ask is this possible or a good practice to load all the data at the start of web app, also i wan't to save it as a cache for offline support, what should i do for this.
Upvotes: 0
Views: 964
Reputation: 116
you can use like this
db.collection("cities").where("state", "==", "CA")
.onSnapshot({ includeMetadataChanges: true }, (snapshot) => {
snapshot.docChanges().forEach((change) => {
if (change.type === "added") {
console.log("New city: ", change.doc.data());
}
var source = snapshot.metadata.fromCache ? "local cache" : "server";
console.log("Data came from " + source);
});
});
https://firebase.google.com/docs/firestore/manage-data/enable-offline
Upvotes: 0
Reputation: 22323
It's a simple principal, but only load data you use at that moment. You don't need book details on a book overview page (for example).
As for storing data and hydrating your state, this can be achieved quite easily with redux-localstorage if you're using the redux. I'm sure you can find another way to add data to local storage if not.
A tip, make sure you save only data you need in local storage and always check if its out of date before applying it to the app.
Upvotes: 2