4

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>
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
LearnToday
  • 2,762
  • 9
  • 38
  • 67
  • 3
    There is no persistence mode for the JavaScript SDK in Firebase at the moment. See this answer: http://stackoverflow.com/questions/32530190/does-firebase-javascript-api-catch-up-with-server-when-re-connected/32530269#32530269 – Frank van Puffelen Sep 03 '16 at 00:44

2 Answers2

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

Fatihd
  • 635
  • 6
  • 12
-1

you can try

firebase.database().goOffline()

and you want to online use

firebase.database().goOnline()