English 中文(简体)
Using Backbone.js offline
原标题:

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.

最佳回答

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:

问题回答

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.

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

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/





相关问题
Inserting PDFs in SQLite

I am developing offline implementation of an iphone app. I cannot insert pdf files into sqlite DB. can anyone help me to insert pdf/xls into sqlite DB. Thanks in advance!

Large XML Files and Pagination, is it possible?

The problem When opening very large XML files locally, on your machine, it s almost a certainty that it will take an age for that file to open - it can often mean your computer locks down because it ...

iPhone UIWebView slow loading to local HTML files

I m developing an app that requires caching web pages (completely) along with their CSS files and images after saving the entire HTML of the page (going through the links to store each file along with ...

Prevent offline iphone webapp from opening link in Safari

I’m developing a website that will work with mobile safari in offline mode. I m able to bookmark it to the home screen and load it from there. But, once opened from the home screen, clicking on ...

Installing Silverlight plugin on offline PC - is it possible?

Let s presume you need to show your shiny new touchscreen-optimised Silverlight application to your boss during trans-atlantic flight. How can you do that on his notebook if the only thing you have is ...

HTML forms working offline

I need to be able to run HTML forms offline. I mean they have to work without direct connection to the web server. In an application I wrote over 5 years ago I did it by implementing a custom ...

热门标签