Socket
Book a DemoInstallSign in
Socket

firetruck.js

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

firetruck.js

Offline caching adapter for Firebase JavaScript API

latest
Source
npmnpm
Version
0.1.1
Version published
Maintainers
1
Created
Source

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 Google. Licensed under an Apache-2.0 license.

Keywords

firebase

FAQs

Package last updated on 25 Apr 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts