Skip to content


Subversion checkout URL

You can clone with
Download ZIP
A localStorage AND sessionStorage adapter for Backbone.js
Branch: master
Pull request Compare This branch is 7 commits ahead of ajpiano:master.

Backbone.webStorage (fork of Backbone.localStorage)

Quite simply an HTML5 WebStorage adapter for Backbone's sync functionality. It's a drop-in replacement for Backbone.Sync() to handle saving to a localStorage or sessionStorage database.


Include Backbone.webStorage after having included Backbone.js:

<script type="text/javascript" src="backbone.js"></script>
<script type="text/javascript" src="backbone.webStorage.js"></script>

Create your collections like so:

window.SomeCollection = Backbone.Collection.extend({

  localStorage: new Backbone.Storage("SomeCollection"), // Unique name within your app - all keys are prepended with this

  // ... everything else is normal.


Feel free to use Backbone as you usually would, this is a drop-in replacement.

LocalStorage versus SessionStorage

Backbone.webStorage supports both localStorage and sessionStorage mechanisms. Default implementation uses localStorage, however you can switch to a sessionStorage mechanism by creating a new Backbone.Storage object with the second optional type parameter. E.g.

localStorage: new Backbone.Storage("SomeCollection", "session"),


Forks from jeromegn (original Backbone.localStorage) and ajpiano for the sessionStorage support. Other bugfixes merged from the network.

Something went wrong with that request. Please try again.