Offline storage using the Backbone.LocalStorage adapter
In the previous section, we saw how overriding the Backbone.sync()
method provides you with customized data operations, including models and collections. Most of the time, we use the HTML5 LocalStorage
functionality to store our data in the browser for offline browsing. This is a pretty common requirement for storing small data in a browser while developing mobile websites and mobile web applications. The LocalStorage
communication can also be done with the help of the sync()
method in a way that is exactly the same as the technique used in the previous section by overriding the sync()
method.
Rather than creating this solution ourselves, we will look into an excellent adapter, Backbone.LocalStorage
(http://documentup.com/jeromegn/backbone.localStorage), which was developed by Jerome Gravel-Niquet and widely used by the Backbone.js developer community for interacting with LocalStorage
. This adapter can be plugged into any model or collection...