node package manager


Backbone localStorage

Backbone localStorage

The package can be installed through npm or bower.

npm install backbone-localstorage
bower install backbone-localstorage

After installing the package, you can grab the backbone-localstorage.js or the minified version of it backbone-localstorage.min.js

When data is fetched via Backbone.sync (models & collections), the reponse will be stored with JSON.stringify in localStorage (before any success method is called). The name under the data is stored is in the following format:


Where prefix is the value set by Backbone.LocalStorage.setPrefix (default unknown) and where url is the remote url from a model or collection.

var model = Backbone.Model.extend({
    urlRoot: '/api/pages',
    localStorage: true
var collection = Backbone.Collection.extend({
    url: '/api/pages',
    localStorage: true
var collection = Backbone.Collection.extend({
    url: '/api/pages',
    localStorage: true

Since many web applications have managable content, it's hard to determine when to recognize new content. The only thing we know about our data is the url and it's timestamp when the data is strored in localStorage. With the method setVerion you can determine in which state of content the localStorage is set. At the point you call this method verions are compared (in strict mode). If the verion is not equal to it's, if present, previous version the localStorage will be cleared (only data set under prefix).


The value may be of any type (int, string, etc.).


  • Fixed url property compatible as a function, not just as a string value


  • Fixed support of localStorage in case of iOS private mode
  • Added tests for storing objects and string (stringified or not)


  • Added forceRefresh option
  • Refactored id to url of model/collection


  • Fixed setVersion clear localStorage when verions differs


  • Fixed issue return null when no localStorage can be found
  • Added documentation

0.1.0 (released on friday, november 15, 2013)

  • Prototype