Store models in localStorage

Now that you know how to store and retrieve data from localStorage, it's time to store your models. In the following figure, you can see how to make data storage in local instead of a remote server.

By default, when you call the save() method on a model Backbone, it transforms the action into an HTTP request for a RESTFul server. To store the data in local, you need to change the default behavior in order to use localStorage instead of making HTTP requests; you will learn how to do this in the next section.

To make the storage layer maintainable, you will need to create a Backbone driver for localStorage first. The responsibility of the driver is to store and retrieve data from localStorage so that the connection between ...

Get Mastering Backbone.js now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.