Chapter 6. Making It Easier with Libraries

“Use the Library, Luke...”

OK, so that may not be exactly how the quote goes, but consider this. Client-side storage is a useful feature of modern browsers. Because it is useful, friendly developers have created libraries to help make using client-side storage even easier. In some cases, these libraries make the APIs easier to use. In some cases, they add features that the native API doesn’t even support. As you can imagine, there are quite a few of these libraries available to you, but in this chapter we’ll look at three in particular: Lockr, Dexie, and localForage.

Working with Lockr

Our first library is Lockr, a wrapper for Web Storage (see Figure 6-1). Right away you may be wondering why in the heck anyone would need to make Web Storage simpler, but stick with me and you’ll see why in a moment. Lockr provides a Redis-like API for Web Storage, but don’t worry if you’ve never heard of Redis. It is a very small library (2.5 KB), and like everything we’ll be covering in this chapter it is free and open source. The Lockr home page may be found here:

Lockr’s home on GitHub
Figure 6-1. Lockr’s home on GitHub

You can grab the source from GitHub or install via Bower: bower install lockr. Once you have the library downloaded, simply include it in your code like any other JavaScript library.

Using Lockr is relatively simple. So, ...

Get Client-Side Data Storage now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.