构建单页应用程序的 JavaScript 框架

我的目标是将现有的 Web 应用程序迁移到 RESTful 单页申请表(SPA)。 目前,我正在评估几个 Javascript web 应用框架。


我的要求如下:

  • RESTful 数据层(如 ember-data)
  • MV *-结构
  • 动态路线
  • 测试-支持
  • 按惯例编码
  • SEO 支持
  • 浏览器-历史-支持
  • 良好的(API -)文档
  • 准备好了
  • 居住社区

骨气

当前应用程序正在使用 backbone.js。总的来说,backbone.js是一个不错的项目,但是我缺少一个定义良好的结构,它决定了在哪里必须发生什么,以及事情必须如何实现。在一个更大的团队中与不断变化的开发人员一起工作,会导致一些非结构化的代码,难以维护,难以理解。这就是为什么我现在正在寻找一个框架,它已经定义了所有这些东西。

微光

前几天我查了 ember.js。我觉得这个方法很有希望。但不幸的是,代码几乎每天都在变化。所以,我不会称之为制作准备。不幸的是,我们不能等到1.0版了。但我真的很喜欢这个框架背后的想法。

角度

Angular.js也是一个广泛传播的框架,由 Google 维护。但我不能熟悉有棱角的。对我来说,结构似乎有点不清楚,对框架每个部分的总体责任的解释缺失,实现感觉迂回。 只是为了弄清楚: 这只是我个人的印象,可能是基于缺失的知识。

蝙蝠侠和流星

据我所知,这两个框架都需要一个服务器部分。由于我们只想要一个 REST 式的后端——不管是什么语言、技术还是软件,这都不是我们想要的。此外,后端 API 已经存在(RoR)。

Knokout CanJS and < a href = “ http://spinejs.com”rel = “ nofollow noReferrer”> Spine

我没有深入调查这三个候选人,也许这就是我的下一步。


所以我现在的问题是:

  • 我错过了什么好的 SPA 框架吗?
  • 您建议/推荐什么框架?
  • 您会避免使用上面提到的任何框架吗?
  • 您在大型 SP 应用程序方面有什么经验?

PS: 我想向 Steven Anderson (Knockout.JS 的核心开发人员)推荐一个关于“ JS 的王座”会议(2012年)和一般的 javascript 框架的 很棒的博客文章

PS: 是的,我知道已经有一些关于 SO 的问题了。但是由于 SPA 的发展如此迅速,大多数 SPA 已经过时了。

75970 次浏览

I recently had to decide on a JavaScript SPA framework on a project too.

  • Ember

    Looked at Ember early on and had similar thoughts as you about it - I really liked it but it felt like it was still too early to use... about half the tutorials I read didn't work with the current version because something had recently changed in how templating works.

  • Backbone

    Backbone was the first frameworks we seriously looked at. I'm not sure I understand why you think it doesn't have "well defined structures"? Backbone is pretty clear about how to divide up Model and View code. Maybe you mean there's not some kind of app template? Anyway, Backbone seems really focused on the model/REST-binding part, but doesn't really prescribe anything for view binding. If model binding's important to you and you're using Rails it should be a breeze to do this. Unfortunately, the web services for my app didn't really match up, and I had to write my own .sync and .parse methods for everything. The separation of Model and View code was nice, but since we'd have to write all our bindings from scratch it wasn't worth it.

  • Knockout

    Knockout is like the Yin to Backbone's Yang. Where Backbone is focused on the Model, Knockout is a MVVM framework and is focused on the View. It has observable wrappers for JavaScript object properties and uses a data-bind attribute to bind properties to your HTML. In the end we went with Knockout since view binding was mainly what we needed for our app. (...plus others, as discussed later...) If you like Knockout's view binding and Backbone's model bindings there's also KnockBack which combines both frameworks.

  • Angular

    Looked at this after Knockout - unfortunately we all seemed pretty happy with how Knockout did view binding. It seemed a lot more complex and harder to get into than Knockout. And it uses a bunch of custom HTML attributes to do bindings, which I'm not sure I like... I may take another look at Angular later, because since I've come across multiple people who really like the framework - maybe we just looked at it too late for this project.

  • Batman, Meteor, CanJS, Spine

    Didn't really look too closely at any of these. Though I know Spine is a similar framework to Backbone with explicit Controller objects, and is written in CoffeeScript.

  • Afterword

    As I mentioned, we ended up using Knockout because, for our project, focusing on view binding was more important. We also ended up using RequireJS for modularization, crossroads and Hasher to handle routing and history, Jasmine for testing, as well as JQuery, Twitter Bootstrap, and Underscore.js (and probably more libraries I'm forgetting at the moment).

    Javascript app development is more like the Java ecosystem than the Rails ecosystem. Rails provides a solid core of stuff you're going to use for every app (Rails framework), and the community provides a lot of customizations on top of that (gems). Java provides... a language. And then you can choose Java EE or Spring or Play or Struts or Tapestry. And choose JDBC or Hibernate or TopLink or Ibatis to talk to the database. And then you can use Ant or Maven or Gradle to build it. And choose Tomcat or Jetty or JBoss or WebLogin to run it in. So there's more emphasis on choosing what you need and what works together than choosing THE framework to use.

it's been a year since we started development on our Cloud services project with numerous SPAs, so it was a big decision, which javascript framework to use for our UI to satisfy our RESTful architecture needs. and after a lot of researches we ended up using Dojo framework .

main features you'll love:

  1. educated community and a team that came up with a perfect design pattern. great conventions and modular/object-oriented architecture. with CrossBrowser programming attitudes :)
  2. MV* structure. build UI widgets with external .htm templates and for production, build all your javascript & templates into a single, minified and small .js
  3. build classes with inheritance. property setters, a lot of function tools.
  4. pub/sub mechanism (named topics in dojo)
  5. a lot of UI controls, from validation form control, dialogs/tooltips to a heavy featured, highly customizable (but lightweight) chart & data-grid solution.
  6. a good unit test system named DOH. it also have a robot to reproduce mouse/keyboard actions.
  7. a querying tool (like JQuery) named NodeList with all jquery features and even a lot of it's plugins.
  8. and the good but not so complete part. it has a JsonRest module to use with your REST services. its a handy tool but it lacks a lot of features.

to overcome these issues, we developed an AJAX poller, error handling and universal, loading & notifications solution. we did it very easily using dojo framework conventions and structures. if you don't want to do that, perhaps you have to use another framework for this part.

looking at great SPAs around the web you'll find out all of them are customized and using multiple frameworks. but our experience with Dojo alone was fantastic. and therefore I suggest you to don't think of any other framework since all of them are incomplete for a SPA. but ultimately you have also another option (which I don't recommend and have no details information on). go with a JAVA framework that is capable of building SPAs, by automatically generating UI & javascript.