Featured in
Architecture & Design

Mini-talks: The Machine Intelligence Landscape: A Venture Capital Perspective by David Beyer. The future of global, trustless transactions on the largest graph: blockchain by Olaf Carlson-Wee. Algorithms for Anti-Money Laundering by Richard Minerich.

Featured in
Operations & Infrastructure

Mini-talks: The Machine Intelligence Landscape: A Venture Capital Perspective by David Beyer. The future of global, trustless transactions on the largest graph: blockchain by Olaf Carlson-Wee. Algorithms for Anti-Money Laundering by Richard Minerich.

Featured in
Enterprise Architecture

Mini-talks: The Machine Intelligence Landscape: A Venture Capital Perspective by David Beyer. The future of global, trustless transactions on the largest graph: blockchain by Olaf Carlson-Wee. Algorithms for Anti-Money Laundering by Richard Minerich.

Going Offline with LocalForage

The Mozilla Foundation has released localForage, a new JavaScript library that promises to simplify the process of storing offline data in web applications.

Although it's not a recent browser technology, offline support has always been too fragmented because of the many choices available. What makes this library unique is the fact that it tries to combine the best of both worlds: the features of some more recent technologies (asynchronism and blob support) with a simple API. This offers a powerful offline capability to web applications, making them closer to their mobile native counterparts and more intuitive for developers to work.

One of the first choices available was localStorage which provided a simple data access for offline storage. However benchmark tests have shown it to be slow, it's synchronous and it cannot handle binary blobs (for example, no mp3 files caching is possible). Since then, two other popular choices have emerged - IndexedDB and Web SQL - which are asynchronous, fast, and support large data sets. The drawback of these two technologies is the fact their APIs aren't very simple to use and neither are supported in all major browsers.

The recently release of localForage tries to overcome these problems by unifying technologies – asynchronism and blob support from IndexedDB and Web SQL with the very simple localStorage syntax:

The inclusion of IndexedDB and Web SQL support allows one to store more data for the web applications than localStorage alone would allow. The non-blocking nature of their APIs makes the web applications faster by not hanging the main thread on get/set calls. Additionally, localForage supports callbacks and ES6 Promises leaving the choice of the best implementation to the developer.

The library automatically loads and manages the drivers for IndexedDB, Web SQL and localStorage so one don’t need to handle this manually (the best driver is chosen independently the browser where the application is running). When neither IndexedDB nor Web SQL are available, localForage falls back to localStorage so at least basic data can be stored offline (though with no blob support and much slower).

All modern browsers are supported by localForage. Asynchronous storage is available in all browsers, with their version that supports localStorage in parentheses: