Your SlideShare is downloading. ×
0
Web App Mvc
Web App Mvc
Web App Mvc
Web App Mvc
Web App Mvc
Web App Mvc
Web App Mvc
Web App Mvc
Web App Mvc
Web App Mvc
Web App Mvc
Web App Mvc
Web App Mvc
Web App Mvc
Web App Mvc
Web App Mvc
Web App Mvc
Web App Mvc
Web App Mvc
Web App Mvc
Web App Mvc
Web App Mvc
Web App Mvc
Web App Mvc
Web App Mvc
Web App Mvc
Web App Mvc
Web App Mvc
Web App Mvc
Web App Mvc
Web App Mvc
Web App Mvc
Web App Mvc
Web App Mvc
Web App Mvc
Web App Mvc
Web App Mvc
Web App Mvc
Web App Mvc
Web App Mvc
Web App Mvc
Web App Mvc
Web App Mvc
Web App Mvc
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Web App Mvc

4,227

Published on

Published in: Technology, Design
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
4,227
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
31
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Web App MVC Jit Im Will 小问
  • 2. Front + Back
  • 3. JavaScript MVC + Node.js MVC
  • 4. Front
  • 5. jQuery MooTools YUI Prototype ExtJS Dojo
  • 6. Mustache.js Underscore.js Backbone.js Socket.io jQuery
  • 7. Back
  • 8. ExpressJS Web.js Connect
  • 9. Underscore.js Socket.io Backbone.js JSData.js MongoSkin Web.js
  • 10. 前后端 MVC 交互 传统 /*PHP*/ $result = mysql_query ( 'SELECT name FROM users' ); while ( $row = mysql_fetch_array ( $result )) { echo " <b> " . $row [ 'name' ]. " </b> " ; echo " <br/> " ; } //jQuery $ . get ( location . origin + '/names.php' ) . done (function ( data ) { $ ( 'body' ). append ( data ); });
  • 11. <ul><li>服务器运算延迟! </li></ul><ul><li>HTTP 传输性能有限! </li></ul><ul><li>终端设备性能大大浪费! </li></ul>
  • 12. 高性能 //Node.js with Web.js and MongoSkin var getRouter = { &apos;names&apos; : function ( req , res , qs ) { db . collection ( &apos;names&apos; ) . find ({}) . toArray (function ( err , names ) { res . sendJSON ( names ); }) } }; web . get ( getRouter ); 前后端 MVC 交互
  • 13. 前后端 MVC 交互 高性能 //jQuery, Mustache.js $ . get ( location . origin + &apos; /names &apos; ) . done (function ( data ) { var $names = JSON . parse (data); $ . get ( location . origin + &apos; /tmlp/names.html &apos; ) . done (function ( data ) { $html = Mustache . to_html (data, {names: $names }); $( &apos; body &apos; ) . append ( $html ); }); });
  • 14. &nbsp;
  • 15. 终端性能 <ul><li>CPU 运算 </li></ul><ul><ul><li>V8 来自 Google 的基于 C++ 的高性能 JavaScript 引擎 </li></ul></ul><ul><ul><li>Worker API 多线程 JavaScript 运行机制 </li></ul></ul><ul><li>GPU 硬件加速 </li></ul><ul><ul><li>Canvas 绘图加速 </li></ul></ul><ul><ul><li>Video API 解码加速 </li></ul></ul><ul><ul><li>DOM 渲染加速 </li></ul></ul><ul><li>移动终端的超强交互性能 </li></ul>
  • 16. 终端性能 <ul><li>存储机制 </li></ul><ul><ul><li>Cookies </li></ul></ul><ul><ul><li>localStorage </li></ul></ul><ul><ul><li>sessionStorage </li></ul></ul><ul><ul><li>Web SQL </li></ul></ul><ul><ul><li>Cache </li></ul></ul><ul><li>交互机制 </li></ul><ul><ul><li>WebSocket </li></ul></ul><ul><ul><li>Message Model </li></ul></ul><ul><ul><li>Ajax Level 2 </li></ul></ul><ul><ul><li>…… </li></ul></ul>不仅不能避免缓存, 而且要主动存储! 不要让 Web 成为 Long Polling 的天下!
  • 17. 服务端资源 ¥ 5800 / 年 Xeon 双核, 1.5G 内存, 150G 存储空间,千兆带宽光纤
  • 18. 服务端资源 ¥ 25500 元 / 年! Xeon 八核, 16G 内存, 750G 存储空间,千兆带宽光纤
  • 19. 服务器资源 <ul><li>HTTP 资源 </li></ul><ul><li>TCP 资源 </li></ul><ul><li>LAN 资源 </li></ul><ul><li>存储资源 </li></ul><ul><li>内存资源 </li></ul><ul><li>数据库资源 </li></ul><ul><li>CPU 资源 </li></ul><ul><li>…… </li></ul>
  • 20. NoSQL 垂直查询 异步通信 关系链 线程运算 垂直查询 关系链 异步通信 NoSQL NoSQL 关系链
  • 21. 前后端优化 Quick Simple Light MVC 高速架构 NoSQL 数据模型 JSON 轻量传输
  • 22. JavaScript — 因为不严谨而飞速发展的脚本语言 Node.js — 基于不严谨的强悍服务器 Web.js — 基于简易的高性能 Node.js 开发框架
  • 23. require ( &apos;webjs&apos; ). run () Simple Deployment
  • 24. File System
  • 25. //ExpressJS var app = require ( &apos;express&apos; ). createServer (); app . get ( &apos;/*&apos; , function ( req , res ) { res . sendfile ( req . get ( &apos;content-disposition&apos; , &apos;filename&apos; )); }); app . listen ( 80 ); //Web.js require ( &apos;webjs&apos; ). run () //Node.js var http = require ( &apos;http&apos; ), fs = require ( &apos;fs&apos; );……… server . on ( &apos;request&apos; , function ( req , res ) { ……… }). listen ( 80 );
  • 26. Node.js MVC
  • 27. M Model
  • 28. &nbsp;
  • 29. var Person = Backbone.Model.extend({ sayHello : function () { console.log(this.get(&apos;name&apos;)); } }); var me = new Person({name: &apos;Will&apos;}); me.sayHello(); // -&gt; &apos;Will&apos;
  • 30. var People = Backbone.Collection.extend({ sayHello : function () { this.map(function (person) { return this.get(&apos;name&apos;) + &apos;say: &amp;quot;Hello, I`m &apos; + this.get(&apos;name&apos;) + &apos;.&amp;quot;n&apos;; }); } }); var w3ctech = new People; w3ctech.add({name: &apos;Will&apos;}, {name: &apos;Foo&apos;}, {name: &apos;Bar&apos;}); w3ctech.sayHello(); /** -&gt; Will say: &amp;quot;Hello, I`m Will.&amp;quot; * Foo say: &amp;quot;Hello, I`m Foo.&amp;quot; * Bar say: &amp;quot;Hello, I`m Bar.&amp;quot; **/
  • 31. V View
  • 32. { Mustache.js
  • 33. Mustache.js &lt; table &gt; &lt; tbody &gt; {{# peoples }} {{# Man }} &lt; tr &gt; &lt; td &gt;{{ Name }}&lt;/ td &gt; &lt; td &gt;{{ Age }}&lt;/ td &gt; &lt; td &gt;{{ Sex }}&lt;/ td &gt; &lt;/ tr &gt; {{/ Man }} {{/ peoples }} &lt;/ tbody &gt; &lt;/ table &gt; 模版
  • 34. Mustache.js var obj = { peoples : [ { Name : &apos;Will&apos; , Age : 15 , Sex : &apos;Man&apos; }, { Name : &apos;Foo&apos; , Age : 30 , Sex : &apos;Woman&apos; }, { Name : &apos;Bar&apos; , Age : 18 , Sex : &apos;Man&apos; }], Man : function () { if ( this . Sex == &apos;Man&apos; ) { return function ( text , render ) { render ( text ); } } } }; 对象
  • 35. Web.js with Mustache.js <ul><li>var getRouter = { </li></ul><ul><li>&apos;^mans&apos; : function ( req , res , qs ) { </li></ul><ul><li>mansHtml = web . render ( &apos;mans&apos; , obj ); </li></ul><ul><li>res . send ( mansHtml ); </li></ul><ul><li>} </li></ul><ul><li>}; </li></ul><ul><li>web . set ( &apos;tmplDir&apos; , &apos;tmlps&apos; ) </li></ul><ul><li>. get ( getRouter ); </li></ul>
  • 36. C Controller
  • 37. Web.js <ul><li>var postRouter = { </li></ul><ul><li>&apos;seturlrouter&apos; : function ( req , res , qs ){ </li></ul><ul><ul><li>web . get ({ qs . key : qs . value }); </li></ul></ul><ul><ul><li>res . send ( &apos;Set success&apos; ); </li></ul></ul><ul><ul><li>} </li></ul></ul><ul><li>}; </li></ul><ul><li>web . post ( postRouter ); </li></ul>
  • 38. JavaScript MVC
  • 39. <ul><li>//For IE </li></ul><ul><li>function parseQs () { </li></ul><ul><li>var qs = ( location . search &gt; 0 ? location . search . substring ( 1 ) : &apos;&apos; ), </li></ul><ul><li>params = {}, </li></ul><ul><li>items = qs . split ( &amp;quot;&amp;&amp;quot; ), </li></ul><ul><li>_item = null ; </li></ul><ul><li>for (var i = 0 ; i &lt; items . length ; i ++) { </li></ul><ul><li>item = items [ i ]; </li></ul><ul><li>params [ decodeURIComponent ( item [ 0 ])] = decodeURIComponent ( item [ 1 ]); </li></ul><ul><li>} </li></ul><ul><li>return params ; </li></ul><ul><li>} </li></ul><ul><li>location . qs = parseOs (); </li></ul>JavaScript MVC
  • 40. JavaScript MVC //For Chrome, FireFox and more location . __defineGetter__ ( &apos;qs&apos; , function() { var qs = ( location . search &gt; 0 ? location . search . substring ( 1 ) : &apos;&apos; ), params = {}, items = qs . split ( &amp;quot;&amp;&amp;quot; ), _item = null ; for (var i = 0 ; i &lt; items . length ; i ++) { item = items [ i ]; params [ decodeURIComponent ( item [ 0 ])] = decodeURIComponent ( item [ 1 ]); } return params ; });
  • 41. JavaScript MVC (function ( $ ) { $ . getScript ( location . origin + &apos;/js/web-client.js&apos; ); //Web.js for Client var getRouter = { &apos;getsomething&apos; : function () { $ ( &apos;body&apos; ). append ( web . getData ( &apos;something&apos; ) . render ( &apos;someTmpl&apos; ) ); } }; web . conn ( location . origin ) . get ( getRouter ) })( jQuery );
  • 42. Page JavaScript MVC Node.js 3.Data Trans 2.Page Action Router 1.Server Router
  • 43. http://www.iwillwen.com https://github.com/iwillwen/Web.js
  • 44. Q&amp;A

×