Backbone.js and jQuery

后端 未结 4 1269
悲&欢浪女
悲&欢浪女 2021-01-29 18:02

It is said that Backbone handles all the higher level abstractions, while jQuery or similar libraries work with the DOM, normalize events and so on..

Could someone pleas

4条回答
  •  滥情空心
    2021-01-29 18:43

    Backbone / Knockout is typically used for single page applications. So while jQuery is a toolbox that can be used with any webpage, Backbone is meant for a specific type of application and helps you organize your code for it. At least in my experience one of the biggest challenges in building a single page app is keeping the code clean and modular, and backbone helps a great deal with this.

    The characteristics of a typical backbone app are:

    • Essentially static html page, with nothing generated on the server
    • Server acts as a json REST api, which provides the content for the app
    • The dom elements to display the data are created with javascript in backbone views, using jQuery and various templating libraries to help
    • Communication with the server as well as between different parts of the app is done through the backbone models

    Regarding your question about keeping the data synced across multiple pages, my instinctive answer is that you don't need multiple pages: the user may perceive that the page is changing, the address in the url bar changes thanks to pushState functionality, but technically the entire app is one page.

    The biggest advantages of this kind of approach are a smooth user experience (no reloading pages), good caching support as everything except the json data is static content, for mobile targets the possibility to turn the web app into a mobile app with phoneGap (because everything except json is static).

提交回复
热议问题