firetruck.js

0.1.1 • Public • Published

Firetruck

Offline caching adapter for Firebase JavaScript API

Firetruck is a proof-of-concept offline caching adapter for the Firebase API. It persists responses through to either IndexedDB, localStorage or WebSQL depending on browser support. This project is targeted at applications with simple to intermediate complexity.

This is not an official Firebase project. It is inspired by previous efforts such as cached-firebase.

Cached Firebase API reading, but not writing supported (for now)

I have previously explored caching for set() operations with queues, however this has been stripped back for now until we can decide on a clean API for handling that problem.

Usage

Add Firetruck to your project

Install Firetruck locally:

$ npm install --save firetruck.js

Require Firetruck in your project:

var Firetruck = require('firetruck.js');

Where you would normally create a new instance of Firebase, create a new Firetruck instance instead. E.g:

Instead of doing:

var api = new Firebase('https://hacker-news.firebaseio.com/v0');

Do this:

var api = new Firetruck('https://hacker-news.firebaseio.com/v0');

Offline caching will work transparently. You can now use methods like .on(), .once(), .child() etc. and in the event of the page being accessed while offline, the browser cache (IDB, LS, WebSQL) will be read for responses instead.

Helpers

Should you need to restore data on pageload (a common requirement), you can call:

api.restore();

If you need to switch off offline-caching, this can be achieved via:

api.switchOffCaching();

switchOnCaching() can be used should you need to turn caching back on after this operation.

Copyright

Copyright Google. Licensed under an Apache-2.0 license.

Package Sidebar

Install

npm i firetruck.js

Weekly Downloads

1

Version

0.1.1

License

Apache-2.0

Last publish

Collaborators

  • addyosmani