原文:ExtJS vs AngularJSjavascript
ExtJS和AngularJS是兩個行業內領先的富界面開發框架。TechFerry有機會使用Ext JS和Angular JS來開發多個富界面的單頁面應用程序。本文講述的就是使用這兩種技術來開發多個應用程序後的開發體驗。本文圍繞利弊、架構、測試、移動能力、性能、生成和部署等方面對Ext JS和Angular JS進行了超過30個以上的要點進行了比較。
咱們將經過使用Ext JS和Angular JS開發一個測試應用程序來了解架構細節,以便進行詳細的性能比較測試。對於性能報告,咱們使用了相似的組件集,採用了固定的生成過程,以確保比較是同類比較。
html
Sencha Ext JS
|
AngularJS
|
Sno | 功能 | ExtJS | AngularJS |
---|---|---|---|
1. | 一站式富界面應用程序 |
|
|
2. | 具備豐富的主題套件能力的UI組件 |
|
幸運的是,有大量的開源的商業組件,爲Angular JS提供了集成組件,包括AngularUI、AngularUI Bootstrap、Kendo(或Angular-Kend)、Wijmo或其餘。 |
3. | 打頁面應用程序的設計 |
|
|
4. | 跨瀏覽器兼容性 |
|
Angular JS依賴於jqLite/JQuery來提供跨瀏覽器的兼容能力。但與其餘第三方庫集成可能須要跨瀏覽器兼容能力。 注意:Angular JS(1.3及以上)已經不支持IE8了,而Sencha Ext JS 5還會繼續支持IE8。若是你的企業用戶須要支持IE8,應考慮Ext JS。 |
5. | 圖表 | Ext JS獨立圖表是業內最強大和最早進的,對於大多數商業應用程序來講,它的插件是免費和足夠應付的。 | AngularJS D3圖表基本上就是集成的D3圖表,這讓它擁有了使人驚異的圖表和圖形繪製功能。使用D3.js,你會愛上D3圖表的。 |
6. | 學習曲線 |
|
|
架構 | |||
7. | 應用程序設計框架 |
還可看看 ExtJS 5 Beta |
它可支持流行的模式,如模型-視圖-控制器或模型-視圖-視圖模型 |
8. | 依賴注入 | 對於依賴注入,Ext JS能夠經過擴充Deft JS來添加Ioc(Inversion of Control,控制反轉)容器。 |
|
9. | 雙向數據綁定 |
|
|
10. | 直接的DOM操做 |
|
|
11. | 模塊化 |
|
|
測試 | |||
12. | 自動化測試支持 | 可經過外部工具實現 |
|
13. | 測試框架或測試運行器 | 一些流行的第三放javascript測試框架,如Siesta(專門爲Ext JS進行了優化)、Jasmine和Mocha,均可用於測試。 | AngularJS依靠它本身的端到端測試運行器(Karma)來實現集成測試。Protractor就是針對Angular應用程序的端到端測試框架。 |
性能 | |||
14. | Dom 算法 | 深度優先、自底往上的算法 | 對於DOM樹,指令是深度優先、自底往上的算法。而對於控制器則是自上往下的方式。 |
15. | 性能 | 較高的覆蓋面/重量,所以Ext JS相對比較慢。 | 在性能測試中,Angular比Ext JS輕3倍。請參閱性能比較統計。 |
16. | 輕量級-較小的下載覆蓋面 |
|
|
移動能力 | |||
17. | Web應用程序的移動支持 | Sencha建議使用Sencha Touch來開發應用程序的移動版本。在移動設備上,像嵌套列表這樣的組件比網格更實用。不過,這意味着須要爲應用程序開發移動版本。 | 使用ng-touch庫實現響應式Web應用程序,angular-gestures(手勢)和AngularJS響應式模塊。 |
18. | 跨平臺本地移動應用程序/混合應用程序 | 經過Sencha Touch集成Apache Cordova/Phonegap實現。 | 經過Trigger.io、Cordova/Phonegap集成基於AngularJS優化過Ionic框架實現,可用來開發富界面和可靠的移動應用程序。 |
19. | 移動網站 | Sencha touch可用來開發移動網站。 | AngularJS響應模塊(angular-responsive, angular-deckgrid等)、UI Boostrap、AngularJS responsive directives, angular-gestures 和ngTouch庫。 |
路由 | |||
20. | 內置路由 |
參閱 ExtJS 5 Beta |
|
21. | 深度連接 |
參閱 ExtJS 5 Beta |
|
22. | 瀏覽器歷史、向前、向後按鈕支持t | 經過Ext.util.History實現 |
|
23. | 瀏覽器書籤支持 |
參閱 ExtJS 5 Beta |
|
24. | SEO支持 |
大多數單頁面應用程序須要經過身份驗證後才能使用,於是通常不須要SEO索引。對於公共頁面,可以使用靜態HTML/CSS來實現,若是須要實現的動態內容,可考慮AjaxBased SEO。 | 可考慮使用Prerender.io或在Web服務器中實現無頭的瀏覽器支持來實現基於Ajax的SEO。 |
部署 | |||
25. | 生成工具 | 針對Ext JS 4.x+的Sencha cmd 工具或針對Ext JS 3.x的Sencha sdk工具 | 第三放的 Grunt 工具 |
26. | 包管理工具 | Sencha cmd | Yeoman, Grunt 或 Bower |
協議和支持 | |||
27. | 協議:開源或商業 | Per-seat / per-server的商業協議或GPL許可下的開源協議 | MT許可下的開源javascript框架 |
28. | 完整的文檔套件、教程、視頻示例、培訓 |
|
|
29. | 支持:通常性討論、Bug報告和定製功能需求 | 基於Web的公共或白金(僅付費的訂閱用戶)支持 |
|
30. | 徹底的樂趣和知足:在整個應用程序開發生命週期內,不須要考慮所選擇的第三庫新版本發佈或bug修復 |
|
|
其餘 | |||
31. | 內置動畫支持 |
|
|
32. | Deferred 和Promises. | DeftJS提供了一些Ext JS擴展,包含了Deferred和Promises. |
|
33. | Dirty Checking(髒檢查) |
|
|
34. | Deferred Bootstrap | Until now, ExtJS applications' testing has never required delay in the Bootstrap as third-party JavaScript testing frameworks which are used for ExtJS application testing do not require deferring the bootstrap. | Angular Scenario Runner and Batrang require Deferred Bootstrap and hence Deferred Bootstrap concept is introduced to allow end to end tests. |
爲了評估這兩個框架的性能,咱們開發了一個包含網格、樹和圖表組件的小型的應用程序。這兩種技術都是按照規定的生成過程來進行的,所以,咱們可使用最小化的生成來進行量級比較。YSlow用來收集性能數據。其餘的細節:
java
Ext JSnode
AngularJS:react
若是使用ext-all,那麼統計結果是:jquery
使用Ext JS:
web
使用AngularJS:
ajax
咱們嘗試從如下10個方面來比較Ext JS和AngularJS之間的架構差別:算法
摘要:
Ext JS是基於組件(網格、樹、表單和圖表)的,代碼開始於擴展的API類和配置模塊,若是須要,可自定義延時文稿或行爲/事件,將這些組件添加到容器/佈局。它遵循面向對象原則和MVC模式,不多須要與DOM直接交互。
AngularJS,恰好相反,它是聲明式編程,開始時,須要在純HTML中添加AngularJS指令、配置模塊、使用模板或路由來配置視圖,並且框架還有關注DOM的建立。因爲要處理HTML,於是須要直接與HTML結構或DOM元素交互。shell
應用程序設計框架 |
||
Ext JS:
|
AngularJS:
|
|
組件: |
||
Ext JS: Ext JS區別於其餘框架的一個主要特性就是包含一套有豐富的主題能力的UI組件。 Pros: 使用Ext JS提供的方便的組件能夠節省大量時間。 Cons: Sencha組件每每會產生冗長的DOM輸出,其結果就是須要更多標籤。 |
AngularJS:
|
|
路由的好處 |
||
ExtJS: Ext JS沒有路由。不過,許多單頁面應用程序可能不須要路由,除非你但願經過內部/深度連接來實現SEO友好性或支持書籤。 |
AngularJS:
|
|
可測試性: |
||
ExtJS:
|
AngularJS:
|
|
雙向數據綁定:雙向數據綁定是應用程序UI和模型對象之間的粘合劑,這樣,對象屬性的改變就會反映到UI,反之亦然。 |
||
ExtJS: 經過使用存儲對象,Ext JS有着優秀的數據綁定功能。爲了執行雙向數據綁定,還須要執行一些工做,如從新加載存儲等等。 |
AngularJS: AngularJS的雙向數據綁定基本上是經過嵌套在原型繼承樹上的模型來實現的。 Cons: 若是模板綁定的數據有2000到3000,應用程序會變得遲鈍。 Bindonce is a great way to minimize the number of watches when most of the data presented in your page, once rendered, are immutable and you need not keep watching them for changes. |
|
SEO Friendliness:Most of the single page apps which work behind authentication need not be indexed for SEO. If you have some pages in your app which are public and which needs to be indexed, you can createthem separately, either with static HTML/CSS or if you do need to use dynamic content, consider Ajaxbased SEO as described below.Ajax based SEO: For the indexing of dynamic / ajax-based single page web apps, all you have to do is to generate the additional static content so that when the crawlers access your page, they get easy access to that static content and when the users access your page, they see the app. To achieve this functionality you could either use some tools like Prerender.io: fully open-source or you have to set up the headless browser support in your web-server which is an additional effort. |
||
ExtJS: Ajax based seo is possible in ExtJS with hashbang urls' support in your web-server. |
AngularJS:
|
|
Mobile Solutions: |
||
ExtJS:
|
AngularJS:
|
|
Dom Approach: |
||
ExtJS: It follows the Depth First, Bottom-Up approach. |
AngularJS: Directives are linked in a Depth-First, Bottom-Up approach to the DOM tree.Controllers are linked in a top-down manner. |
|
Deferred and Promises:Deferred and Promises break the complexities of asynchronous programming, separate out the synchronous and asynchronous world, remove the tight coupling between the twoThey are for asynchronous programming what try, catch and throw keywords are for synchronous programming. |
||
ExtJS: ExtJS augmented with DeftJS may provide Deferred and Promises. |
AngularJS: AngularJS offers an implementation of the Q API for Deferred and Promises. |
|
Dirty CheckingDirty checking in nutshell: The framework compares the old value and new value and if they are different, fires the change event. |
||
ExtJS:
|
AngularJS:
|
|
Deferred bootstrap:Bootstrap means the initialization process. Deferred bootstrap is to make a delay in the bootstrap process to mock out the heavy dependencies or for the instrumentation purposes. Deferred bootstrap is primarily introduced to allow end to end tests.Although deferred bootstrap has no value in the developement and testing of most single page applications, yet it serves its value in AngularJS applications' end to end testing. Some javascript test runners such as Batrang and Angular Scenario Runner (which are developed by AngularJS team for the end to end testing of the angularJS applications) require deferred bootstrap. |
||
ExtJS: Several popular third-party JavaScript testing frameworks such as Siesta (optimized specifically for Ext JS), Jasmine and Mocha, are being used for ExtJS applications testing which do not require deferring the ExtJS application's bootstrap. |
AngularJS:
|
|
Digest Cycle in AngularJS:
Application becomes laggy if there are 2000-3000 watches in a template. Although anything faster than 50ms is imperceptible to humans and you can't really show more than about 2000 pieces of information to a human on a single page because anything more than that is really a bad UI and humans can't process this anyway, yet while building any sort of widget or data grid with two-way binding you may easily hit 2000 bindings without the bad UI. Watcher: By default all the model data that is bound to UI are being watched upon i.e. they all have a watcher registered in the watch list, a collection used by digest cycle for the dirty checking. You can also attach a watcher to the scope by using $watch function. A watcher has two functions: A watch function or a watch expression, which specifies the piece of data you are interested in. A listener function which will be called whenever that data changes. Asynchronous nature of dirty cycle: Assignment such as $scope.username="angular" will not immediately cause a $watch to be notified, instead the $watch notification is delayed until the $digest phase. This delay is desirable, since it coalesces multiple model updates into one $watch notification as well as it guarantees that during the $watch notification no other $watches are running. If a $watch changes the value of the model, it will force additional $digest cycle. |
||
ExtJS 5 Beta:Recently launched ExtJS5 Beta version provides support for router and hence deep linking is now possible.ExtJS 5 also supports MVC and MVVM.We will review and update the article as and when new and stable versions of ExtJS and AngularJS are released. |