Using Backbone.js offline

12.4k views Asked by At

I'm evaluating Backbone.js for keeping data and UI synchronized in my web app. However, much of Backbone's value seems to lie in its use of RESTful interfaces. Though I may add server-side backup in the future, my primary use case involves storing all data offline using HTML5 local storage.

Is Backbone overkill for such a use case? If so, is there a better solution, focused solely on updating UI when data changes, and vice versa? (I'm also looking into Knockout and Javascript MVC.)

EDIT: I'm also now looking into Angular.js and jQuery Data Link.

4

There are 4 answers

0
DaveJ On BEST ANSWER

Backbone.js works just as well with local storage as it does with RESTful queries.

I'm a learn-by-example kind of guy so here are some links to get you started:

0
lbz On

In the past weeks I have evaluated different solution for a scenario close to yours; being a project done in my personal free time and not being a good Javascript programmer, all I needed was something easy to learn to avoid starting from scratch.

Not surprisingly, I had the same candidate: Backbone.js, Javascript MVC and Knockout.js.

Backbone.js won:

  • I wasn't be required to follow conventions or replace what was already in place
  • I've easly hacked in its codebase to understand what wasn't clear from the documentation
  • I've successfully ignored a large amount of its features that was not interesting for me
  • It gave acceptable performance on busy pages
  • It works

Backbone.js is lightweight and relatively magic-free; you will probably use a small subset of its feature but it provieds a solid base to develop your solution.

0
Shane Tomlinson On

You can also take a look at AFrameJS. I have created a bare-bones proof of concept note-taking app that works offline using HTML5 WebSQL spec, but also want to create an adapter that uses localStorage as well. My personal opinion (and I am biased) is that using an MVC library of any sorts is going to help you in the long run - the value of libraries such as Backbone, Knockout, and AFrame lie in their ability to reduce the cognitive load of the developer by enforcing a good separation of concerns. Data related functionality reside in models, displaying that data resides in Views, and the glue is kept in Controllers. Separating these three concepts might seem pedantic at first, but the end result is code that is easier to develop, easier to test, easier to maintain, and easier to reuse. A basic tutorial on using AFrameJS can be found on my site at: http://www.shanetomlinson.com/2011/aframejs-tutorial-for-noobs/

0
dineth On

I know it's been a while but you may want to check out backbone-offline project on github: https://github.com/Ask11/backbone.offline