Giter VIP home page Giter VIP logo

offline-firebase's Introduction

offline-firebase

A Firebase wrapper that stores a cache of your data offline in localStorage when there is no internet connection available.

I built this for use in a PhoneGap application that I am developing. The idea is that if a user is in offline mode (e.g. on an airplane) the app should continue to work and then sync with the server once an internet connection is available.

Firebase handles the syncing once the server is available part natively.

This extension adds cold-start support to repopulate Firebase's local cache with data that has been stored in localStorage.

To use this, you'll need to include the unminified Firebase script on your site. It is available on their CDN here: http://cdn.firebase.com/v0/firebase-debug.js

(You will obviously want to download it and include it with your app rather than linking to the CDN for use in offline mode.)

You will also need to include OfflineFirebase.js from this repository.

Then replace your calls to Firebase with OfflineFirebase and pass a fifth parameter to .on() or .once() to enable the offline caching.

When your app starts up, if you don't have an internet connection available, call OfflineFirebase.restore() to repopulate from your localStorage cache.

Here's an example:

OfflineFirebase.restore();
var f = new OfflineFirebase('https://example.firebaseio.com');
f.on('value', function(snapshot) {
    console.log(snapshot.val());
}, undefined, undefined, true);

Close your application completely and turn on airplane mode. When you re-open it and run the above, your data will still log out because it has been persisted through localStorage.

offline-firebase's People

Contributors

adjohnson916 avatar yeldarby avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.