SlideShare une entreprise Scribd logo
1  sur  44
Web App MVC Jit Im Will 小问
Front + Back
JavaScript MVC + Node.js MVC
Front
jQuery MooTools YUI Prototype ExtJS Dojo
Mustache.js Underscore.js Backbone.js Socket.io jQuery
Back
ExpressJS Web.js Connect
Underscore.js Socket.io Backbone.js JSData.js MongoSkin Web.js
前后端 MVC 交互 传统 /*PHP*/ $result  =  mysql_query ( 'SELECT name FROM users' ); while  ( $row  =  mysql_fetch_array ( $result )) { echo   &quot; <b> &quot; . $row [ 'name' ]. &quot; </b> &quot; ; echo   &quot; <br/> &quot; ; } //jQuery $ . get ( location . origin  +  '/names.php' ) . done (function ( data ) { $ ( 'body' ). append ( data ); });
[object Object],[object Object],[object Object]
高性能 //Node.js with Web.js and MongoSkin var  getRouter  = { 'names'  : function ( req ,  res ,  qs ) { db . collection ( 'names' )   . find ({})   . toArray (function ( err ,  names ) { res . sendJSON ( names );   }) } }; web . get ( getRouter ); 前后端 MVC 交互
前后端 MVC 交互 高性能 //jQuery, Mustache.js $ . get ( location . origin  +  ' /names ' ) . done (function ( data ) { var  $names  =  JSON . parse (data); $ . get ( location . origin  +  ' /tmlp/names.html ' ) . done (function ( data ) { $html  =  Mustache . to_html (data, {names: $names }); $( ' body ' ) . append ( $html ); }); });
 
终端性能 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
终端性能 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],不仅不能避免缓存, 而且要主动存储! 不要让 Web 成为 Long Polling 的天下!
服务端资源 ¥ 5800 /  年 Xeon 双核, 1.5G 内存, 150G 存储空间,千兆带宽光纤
服务端资源 ¥ 25500 元  /  年! Xeon 八核, 16G 内存, 750G 存储空间,千兆带宽光纤
服务器资源 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
NoSQL 垂直查询 异步通信 关系链 线程运算 垂直查询 关系链 异步通信 NoSQL NoSQL 关系链
前后端优化 Quick  Simple  Light MVC 高速架构 NoSQL 数据模型 JSON 轻量传输
JavaScript —  因为不严谨而飞速发展的脚本语言 Node.js —  基于不严谨的强悍服务器 Web.js —  基于简易的高性能 Node.js 开发框架
require ( 'webjs' ). run () Simple Deployment
File System
//ExpressJS var  app  =  require ( 'express' ). createServer (); app . get ( '/*' , function ( req ,  res ) { res . sendfile ( req . get ( 'content-disposition' ,  'filename' )); }); app . listen ( 80 ); //Web.js require ( 'webjs' ). run () //Node.js var  http  =  require ( 'http' ), fs  =  require ( 'fs' );……… server . on ( 'request' , function ( req ,  res ) { ……… }). listen ( 80 );
Node.js MVC
M Model
 
var Person = Backbone.Model.extend({ sayHello : function () { console.log(this.get('name')); } }); var me = new Person({name: 'Will'}); me.sayHello();  // -> 'Will'
var People = Backbone.Collection.extend({ sayHello : function () { this.map(function (person) { return this.get('name') + 'say: &quot;Hello, I`m ' + this.get('name') + '.&quot;'; }); } }); var w3ctech = new People; w3ctech.add({name: 'Will'}, {name: 'Foo'}, {name: 'Bar'}); w3ctech.sayHello();  /** -> Will say: &quot;Hello, I`m Will.&quot;   *  Foo say: &quot;Hello, I`m Foo.&quot;   *  Bar say: &quot;Hello, I`m Bar.&quot;   **/
V View
{ Mustache.js
Mustache.js < table > < tbody > {{# peoples }} {{# Man }} < tr > < td >{{ Name }}</ td > < td >{{ Age }}</ td > < td >{{ Sex }}</ td > </ tr > {{/ Man }} {{/ peoples }} </ tbody > </ table > 模版
Mustache.js var  obj  = { peoples  : [ { Name :  'Will' , Age :  15 , Sex :  'Man' }, { Name :  'Foo' , Age :  30 , Sex :  'Woman' }, { Name :  'Bar' , Age :  18 , Sex :  'Man' }], Man  : function () { if ( this . Sex  ==  'Man' ) { return function ( text ,  render ) { render ( text ); } } } }; 对象
Web.js with Mustache.js ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
C Controller
Web.js ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
JavaScript MVC
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],JavaScript MVC
JavaScript MVC //For Chrome, FireFox and more location . __defineGetter__ ( 'qs' ,   function() { var  qs  = ( location . search  >  0  ?  location . search . substring ( 1 ) :  '' ), params  = {}, items  =  qs . split ( &quot;&&quot; ), _item  =  null ; for  (var  i  =  0 ;  i  <  items . length ;  i ++) { item  =  items [ i ]; params [ decodeURIComponent ( item [ 0 ])] =  decodeURIComponent ( item [ 1 ]); } return   params ; });
JavaScript MVC (function ( $ ) { $ . getScript ( location . origin  +  '/js/web-client.js' ); //Web.js for Client var  getRouter  = { 'getsomething'  : function () { $ ( 'body' ). append ( web . getData ( 'something' ) . render ( 'someTmpl' ) ); } }; web . conn ( location . origin ) . get ( getRouter ) })( jQuery );
Page JavaScript MVC Node.js 3.Data Trans 2.Page Action Router 1.Server Router
http://www.iwillwen.com https://github.com/iwillwen/Web.js
Q&A

Contenu connexe

Tendances

Modernizerを用いたHTML5Webサイトの構築
Modernizerを用いたHTML5Webサイトの構築Modernizerを用いたHTML5Webサイトの構築
Modernizerを用いたHTML5Webサイトの構築Hiroaki Wakamatsu
 
Introduction to Service Worker
Introduction to Service WorkerIntroduction to Service Worker
Introduction to Service WorkerShogo Sensui
 
Node.js Scalability Tips
Node.js Scalability TipsNode.js Scalability Tips
Node.js Scalability TipsLuciano Mammino
 
Java Script - Object-Oriented Programming
Java Script - Object-Oriented ProgrammingJava Script - Object-Oriented Programming
Java Script - Object-Oriented Programmingintive
 
第二节课:html5 – web开发步入新阶段
第二节课:html5 – web开发步入新阶段第二节课:html5 – web开发步入新阶段
第二节课:html5 – web开发步入新阶段Tommy Chang
 
이승재, 강성훈, 내가 만든 언어의 개발환경을 Visual Studio Code로 빠르고 쉽게 구축하기 #2, NDC2017
이승재, 강성훈, 내가 만든 언어의 개발환경을 Visual Studio Code로 빠르고 쉽게 구축하기 #2, NDC2017이승재, 강성훈, 내가 만든 언어의 개발환경을 Visual Studio Code로 빠르고 쉽게 구축하기 #2, NDC2017
이승재, 강성훈, 내가 만든 언어의 개발환경을 Visual Studio Code로 빠르고 쉽게 구축하기 #2, NDC2017devCAT Studio, NEXON
 
jQuery - Javascript para quem não sabe Javascript
jQuery - Javascript para quem não sabe JavascriptjQuery - Javascript para quem não sabe Javascript
jQuery - Javascript para quem não sabe JavascriptNando Vieira
 
Node.js をさりげなく取り入れた 最近のフロントエンド事情について
Node.js をさりげなく取り入れた 最近のフロントエンド事情についてNode.js をさりげなく取り入れた 最近のフロントエンド事情について
Node.js をさりげなく取り入れた 最近のフロントエンド事情についてkamiyam .
 
Javascript and jQuery for Mobile
Javascript and jQuery for MobileJavascript and jQuery for Mobile
Javascript and jQuery for MobileIvano Malavolta
 
jQueryでつくる、動きのあるWebページ - 多摩美 メディアリテラシー
jQueryでつくる、動きのあるWebページ - 多摩美 メディアリテラシーjQueryでつくる、動きのあるWebページ - 多摩美 メディアリテラシー
jQueryでつくる、動きのあるWebページ - 多摩美 メディアリテラシーAtsushi Tadokoro
 

Tendances (20)

Jsoon
JsoonJsoon
Jsoon
 
Modernizerを用いたHTML5Webサイトの構築
Modernizerを用いたHTML5Webサイトの構築Modernizerを用いたHTML5Webサイトの構築
Modernizerを用いたHTML5Webサイトの構築
 
Introduction to Service Worker
Introduction to Service WorkerIntroduction to Service Worker
Introduction to Service Worker
 
Slay
SlaySlay
Slay
 
Jquery ui, ajax
Jquery ui, ajaxJquery ui, ajax
Jquery ui, ajax
 
Node.js Scalability Tips
Node.js Scalability TipsNode.js Scalability Tips
Node.js Scalability Tips
 
Service Workers
Service WorkersService Workers
Service Workers
 
Java Script - Object-Oriented Programming
Java Script - Object-Oriented ProgrammingJava Script - Object-Oriented Programming
Java Script - Object-Oriented Programming
 
Modelo Php
Modelo PhpModelo Php
Modelo Php
 
第二节课:html5 – web开发步入新阶段
第二节课:html5 – web开发步入新阶段第二节课:html5 – web开发步入新阶段
第二节课:html5 – web开发步入新阶段
 
Dart und JavaScript
Dart und JavaScriptDart und JavaScript
Dart und JavaScript
 
이승재, 강성훈, 내가 만든 언어의 개발환경을 Visual Studio Code로 빠르고 쉽게 구축하기 #2, NDC2017
이승재, 강성훈, 내가 만든 언어의 개발환경을 Visual Studio Code로 빠르고 쉽게 구축하기 #2, NDC2017이승재, 강성훈, 내가 만든 언어의 개발환경을 Visual Studio Code로 빠르고 쉽게 구축하기 #2, NDC2017
이승재, 강성훈, 내가 만든 언어의 개발환경을 Visual Studio Code로 빠르고 쉽게 구축하기 #2, NDC2017
 
jQuery - Javascript para quem não sabe Javascript
jQuery - Javascript para quem não sabe JavascriptjQuery - Javascript para quem não sabe Javascript
jQuery - Javascript para quem não sabe Javascript
 
Node.js をさりげなく取り入れた 最近のフロントエンド事情について
Node.js をさりげなく取り入れた 最近のフロントエンド事情についてNode.js をさりげなく取り入れた 最近のフロントエンド事情について
Node.js をさりげなく取り入れた 最近のフロントエンド事情について
 
Poetry in the age of hip-hop
Poetry in the age of hip-hopPoetry in the age of hip-hop
Poetry in the age of hip-hop
 
Javascript and jQuery for Mobile
Javascript and jQuery for MobileJavascript and jQuery for Mobile
Javascript and jQuery for Mobile
 
Local storages
Local storagesLocal storages
Local storages
 
Dart != JavaScript
Dart != JavaScriptDart != JavaScript
Dart != JavaScript
 
jQueryでつくる、動きのあるWebページ - 多摩美 メディアリテラシー
jQueryでつくる、動きのあるWebページ - 多摩美 メディアリテラシーjQueryでつくる、動きのあるWebページ - 多摩美 メディアリテラシー
jQueryでつくる、動きのあるWebページ - 多摩美 メディアリテラシー
 
Wek14 mysql 2
Wek14 mysql 2Wek14 mysql 2
Wek14 mysql 2
 

En vedette

Focus on the outside, testing in ASP.NET MVC
Focus on the outside, testing in ASP.NET MVCFocus on the outside, testing in ASP.NET MVC
Focus on the outside, testing in ASP.NET MVCRob Ashton
 
F# Eye for the C# Guy - DDD North 2013
F# Eye for the C# Guy - DDD North 2013F# Eye for the C# Guy - DDD North 2013
F# Eye for the C# Guy - DDD North 2013Phillip Trelford
 
Controller Testing: You're Doing It Wrong
Controller Testing: You're Doing It WrongController Testing: You're Doing It Wrong
Controller Testing: You're Doing It Wrongjohnnygroundwork
 
ASP.NET MVC Fundamental
ASP.NET MVC FundamentalASP.NET MVC Fundamental
ASP.NET MVC Fundamentalldcphuc
 
Unit Testing in JavaScript with MVC and QUnit
Unit Testing in JavaScript with MVC and QUnitUnit Testing in JavaScript with MVC and QUnit
Unit Testing in JavaScript with MVC and QUnitLars Thorup
 
DDD, CQRS and testing with ASP.Net MVC
DDD, CQRS and testing with ASP.Net MVCDDD, CQRS and testing with ASP.Net MVC
DDD, CQRS and testing with ASP.Net MVCAndy Butland
 
Laws of test automation framework
Laws of test automation frameworkLaws of test automation framework
Laws of test automation frameworkvodqancr
 
CQRS на практике. В поиске точки масштабирования и новых метафор
CQRS на практике. В поиске точки масштабирования и новых метафорCQRS на практике. В поиске точки масштабирования и новых метафор
CQRS на практике. В поиске точки масштабирования и новых метафорAlexander Byndyu
 
Unit and integration Testing
Unit and integration TestingUnit and integration Testing
Unit and integration TestingDavid Berliner
 
Behavior Driven Development with Cucumber
Behavior Driven Development with CucumberBehavior Driven Development with Cucumber
Behavior Driven Development with CucumberBrandon Keepers
 

En vedette (12)

Focus on the outside, testing in ASP.NET MVC
Focus on the outside, testing in ASP.NET MVCFocus on the outside, testing in ASP.NET MVC
Focus on the outside, testing in ASP.NET MVC
 
F# Eye for the C# Guy - DDD North 2013
F# Eye for the C# Guy - DDD North 2013F# Eye for the C# Guy - DDD North 2013
F# Eye for the C# Guy - DDD North 2013
 
Controller Testing: You're Doing It Wrong
Controller Testing: You're Doing It WrongController Testing: You're Doing It Wrong
Controller Testing: You're Doing It Wrong
 
ASP.NET MVC Fundamental
ASP.NET MVC FundamentalASP.NET MVC Fundamental
ASP.NET MVC Fundamental
 
Unit Testing in JavaScript with MVC and QUnit
Unit Testing in JavaScript with MVC and QUnitUnit Testing in JavaScript with MVC and QUnit
Unit Testing in JavaScript with MVC and QUnit
 
DDD, CQRS and testing with ASP.Net MVC
DDD, CQRS and testing with ASP.Net MVCDDD, CQRS and testing with ASP.Net MVC
DDD, CQRS and testing with ASP.Net MVC
 
Laws of test automation framework
Laws of test automation frameworkLaws of test automation framework
Laws of test automation framework
 
CQRS на практике. В поиске точки масштабирования и новых метафор
CQRS на практике. В поиске точки масштабирования и новых метафорCQRS на практике. В поиске точки масштабирования и новых метафор
CQRS на практике. В поиске точки масштабирования и новых метафор
 
Unit and integration Testing
Unit and integration TestingUnit and integration Testing
Unit and integration Testing
 
Model View Controller (MVC)
Model View Controller (MVC)Model View Controller (MVC)
Model View Controller (MVC)
 
Mvc architecture
Mvc architectureMvc architecture
Mvc architecture
 
Behavior Driven Development with Cucumber
Behavior Driven Development with CucumberBehavior Driven Development with Cucumber
Behavior Driven Development with Cucumber
 

Web App Mvc

  • 1. Web App MVC Jit Im Will 小问
  • 3. JavaScript MVC + Node.js MVC
  • 5. jQuery MooTools YUI Prototype ExtJS Dojo
  • 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 &quot; <b> &quot; . $row [ 'name' ]. &quot; </b> &quot; ; echo &quot; <br/> &quot; ; } //jQuery $ . get ( location . origin + '/names.php' ) . done (function ( data ) { $ ( 'body' ). append ( data ); });
  • 11.
  • 12. 高性能 //Node.js with Web.js and MongoSkin var getRouter = { 'names' : function ( req , res , qs ) { db . collection ( 'names' ) . find ({}) . toArray (function ( err , names ) { res . sendJSON ( names ); }) } }; web . get ( getRouter ); 前后端 MVC 交互
  • 13. 前后端 MVC 交互 高性能 //jQuery, Mustache.js $ . get ( location . origin + ' /names ' ) . done (function ( data ) { var $names = JSON . parse (data); $ . get ( location . origin + ' /tmlp/names.html ' ) . done (function ( data ) { $html = Mustache . to_html (data, {names: $names }); $( ' body ' ) . append ( $html ); }); });
  • 14.  
  • 15.
  • 16.
  • 17. 服务端资源 ¥ 5800 / 年 Xeon 双核, 1.5G 内存, 150G 存储空间,千兆带宽光纤
  • 18. 服务端资源 ¥ 25500 元 / 年! Xeon 八核, 16G 内存, 750G 存储空间,千兆带宽光纤
  • 19.
  • 20. NoSQL 垂直查询 异步通信 关系链 线程运算 垂直查询 关系链 异步通信 NoSQL NoSQL 关系链
  • 21. 前后端优化 Quick Simple Light MVC 高速架构 NoSQL 数据模型 JSON 轻量传输
  • 22. JavaScript — 因为不严谨而飞速发展的脚本语言 Node.js — 基于不严谨的强悍服务器 Web.js — 基于简易的高性能 Node.js 开发框架
  • 23. require ( 'webjs' ). run () Simple Deployment
  • 25. //ExpressJS var app = require ( 'express' ). createServer (); app . get ( '/*' , function ( req , res ) { res . sendfile ( req . get ( 'content-disposition' , 'filename' )); }); app . listen ( 80 ); //Web.js require ( 'webjs' ). run () //Node.js var http = require ( 'http' ), fs = require ( 'fs' );……… server . on ( 'request' , function ( req , res ) { ……… }). listen ( 80 );
  • 28.  
  • 29. var Person = Backbone.Model.extend({ sayHello : function () { console.log(this.get('name')); } }); var me = new Person({name: 'Will'}); me.sayHello(); // -> 'Will'
  • 30. var People = Backbone.Collection.extend({ sayHello : function () { this.map(function (person) { return this.get('name') + 'say: &quot;Hello, I`m ' + this.get('name') + '.&quot;'; }); } }); var w3ctech = new People; w3ctech.add({name: 'Will'}, {name: 'Foo'}, {name: 'Bar'}); w3ctech.sayHello(); /** -> Will say: &quot;Hello, I`m Will.&quot; * Foo say: &quot;Hello, I`m Foo.&quot; * Bar say: &quot;Hello, I`m Bar.&quot; **/
  • 33. Mustache.js < table > < tbody > {{# peoples }} {{# Man }} < tr > < td >{{ Name }}</ td > < td >{{ Age }}</ td > < td >{{ Sex }}</ td > </ tr > {{/ Man }} {{/ peoples }} </ tbody > </ table > 模版
  • 34. Mustache.js var obj = { peoples : [ { Name : 'Will' , Age : 15 , Sex : 'Man' }, { Name : 'Foo' , Age : 30 , Sex : 'Woman' }, { Name : 'Bar' , Age : 18 , Sex : 'Man' }], Man : function () { if ( this . Sex == 'Man' ) { return function ( text , render ) { render ( text ); } } } }; 对象
  • 35.
  • 37.
  • 39.
  • 40. JavaScript MVC //For Chrome, FireFox and more location . __defineGetter__ ( 'qs' , function() { var qs = ( location . search > 0 ? location . search . substring ( 1 ) : '' ), params = {}, items = qs . split ( &quot;&&quot; ), _item = null ; for (var i = 0 ; i < items . length ; i ++) { item = items [ i ]; params [ decodeURIComponent ( item [ 0 ])] = decodeURIComponent ( item [ 1 ]); } return params ; });
  • 41. JavaScript MVC (function ( $ ) { $ . getScript ( location . origin + '/js/web-client.js' ); //Web.js for Client var getRouter = { 'getsomething' : function () { $ ( 'body' ). append ( web . getData ( 'something' ) . render ( 'someTmpl' ) ); } }; web . conn ( location . origin ) . get ( getRouter ) })( jQuery );
  • 42. Page JavaScript MVC Node.js 3.Data Trans 2.Page Action Router 1.Server Router
  • 44. Q&A