5

I am trying to make my firebase app work offline. In the documentation, it talks of disk persistent in android using

Firebase.getDefaultConfig().setPersistenceEnabled(true);

I was wndering if there is anyway to get such a feature for a web app so I can cache my firebase database and my site to still function even when offline.

  <script>
  // Initialize Firebase
  var config = {
    apiKey: "AIzaSycccccceeeeeeeeeeeeeeeeeee",
    authDomain: "gotube-ccccc.firebaseapp.com",
    databaseURL: "https://gotube-ccccc.firebaseio.com",
    storageBucket: "gotube-cccc.appspot.com",
  };

  firebase.initializeApp(config);
  firebase.getDefaultConfig().setPersistenceEnabled(true);

</script>
1

2 Answers 2

0

There is a persistence option in Firestore web sdk.

You can get all information from here

    firebase.firestore().enablePersistence()
      .catch(function(err) {
       if (err.code == 'failed-precondition') {
          // Multiple tabs open, persistence can only be enabled
          // in one tab at a a time.
          // ...
       } else if (err.code == 'unimplemented') {
          // The current browser does not support all of the
          // features required to enable persistence
          // ...
       }
    });
    // Subsequent queries will use persistence, if it was enabled successfully

There are more options in Realtime Database.

You can handle offline capabilities by many ways. The page is here

Sign up to request clarification or add additional context in comments.

Comments

-1

you can try

firebase.database().goOffline()

and you want to online use

firebase.database().goOnline()

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.