O'Reilly logo

Client-Side Data Storage by Raymond Camden

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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: https://github.com/tsironis/lockr.

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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required