Top Banner
Yakov Fain, Farata Systems 7 Versions of One Web Application
54

Seven Versions of One Web Application

May 10, 2015

Download

Technology

Yakov Fain

These are the presentation slides demonstratingseven versions of the UI of same HTML5 application using various libraries and frameworks. This application is described in detail in the O'Reilly book "Enterprise Web Development"
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Seven Versions of One Web Application

Yakov Fain, Farata Systems

7 Versions of One Web Application

Page 2: Seven Versions of One Web Application

www.faratasystems.com  

Page 3: Seven Versions of One Web Application

We’ll  Review  7  Versions  of  the  UI  of  this  Single  Page  Applica?on  

SPA:  One  Web  page,  AJAX  calls  bring  the  data  as  needed,  CSS  hides/shows  HTML  elements  

Page 4: Seven Versions of One Web Application

…  and  the  7  versions  are…  

1.  HTML/AJAX  

2.  HTML  +  Responsive  Web  Design  

3.  With  jQuery  library    

4.  With  Ext  JS  framework  

5.  Modularizing  HTML5  

6.  With  jQuery  Mobile  

7.  With  Sencha  Touch  

Page 5: Seven Versions of One Web Application

Wireframing  with  Balsamiq  Mockups  

Page 6: Seven Versions of One Web Application

V1:  HTML,  JS,  CSS,  AJAX,  JSON  //  Loading  data    with  AJAX  and  parsing  JSON                                  func9on  loadData(dataUrl)  {  

 var  xhr  =  new  XMLH+pRequest();      

 xhr.open('GET',  dataUrl,  true);    

 xhr.onreadystatechange  =  func9on()  {      if  (xhr.readyState  ==  4)  {        if  (xhr.status  ==  200)  {          var  jsonData  =  xhr.responseText;  

         //parse  json  data          var  campaignsData  =  JSON.parse(jsonData).campaigns;          showCampaignsInfo(campaignsData);        }  else  {          console.log(xhr.statusText);        }      }    }    xhr.send(null);  

}  

Page 7: Seven Versions of One Web Application

Demo:  Debugging  in  Chrome  

Page 8: Seven Versions of One Web Application

Oops…A  Smaller  Screen  

Page 9: Seven Versions of One Web Application

V2:  Responsive  Web  Design(RWD)  •  Should  we  create  separate  versions  for  desktop  and  mobile?  

•  How  many  versions  of  the  UI  to  create?  

•  Can  we  have  a  single  HTML  version  for  all  devices?  

•  CSS  Media  Queries  –    layouts  based  on  screen  width  

•  Seing  CSS  Breakpoints  

•  Pros  and  Cons  of  RWD    

Page 10: Seven Versions of One Web Application

Remember  the  wireframe  for  desktops?  

Page 11: Seven Versions of One Web Application

Wireframing  for  a  table  in  portrait    

Page 12: Seven Versions of One Web Application

Wireframing  for  large  phones  

Page 13: Seven Versions of One Web Application

Wireframing  for  smaller  phones  

These  are  the  wireframes  for  3  phone  screens  

Page 14: Seven Versions of One Web Application

V2:  Demo  

1.  Basic  Media  Queries  2.  Responsive  Header  3.  Responsive  

Dona?on  4.  Responsive  Final  

Page 15: Seven Versions of One Web Application

RWD  Pros  and  Cons  •  RWD  is  good  for  publishing  info.  Mobile  frameworks  can  be  a  

beker  choice  for  interac?ve  apps  

•  RWD  allows  to  have  a  single  app  code  base  

•  Mobile  versions  of  an  app  may  need  limited  func?onality  and  

specific  naviga?on  

•  RWD  means  larger  traffic  (heavy  CSS)  –  no  good  for  slower  

connec?ons  

•  Mobile  frameworks  offer  more  na?ve  look  and  feel  of  the  UI    

Libraries  of  responsive  UI  components:  Bootstrap:  hkp://getbootstrap.com  Seman?c  UI:  hkp://seman?c-­‐ui.com          

Page 16: Seven Versions of One Web Application

V3:  With  jQuery  Library  •  Learning  jQuery  is  easy  for  designers  –  mostly  HTML.  

•  40  –  50%  of  top  Web  sites  use  jQuery  (see  bultwith.com)        

•  It’s  a  light-­‐weight  addi?on  to  your  app  –  33Kb  gzipped,  minified  

•  Shorter  than  in  JS  syntax  for  DOM  Browsing    

•  $()  –  pass  it  a  String,    pass  it  a  func?on    

•  There  are  thousands  plugins  in  jQuery  Plugin  Registry  

Page 17: Seven Versions of One Web Application

DOM  Querying  &  Func?on  Chaining  

Page 18: Seven Versions of One Web Application

An  AJAX  call  in  jQuery  

The  shortcut  methods:  $.get(),  $.post(),  $.getJSON()  

Page 19: Seven Versions of One Web Application

V3:  Demo  with  jQuery  

Page 20: Seven Versions of One Web Application

V4:  With  Sencha  Ext  JS  Framework  •  Ext  JS  has  rich  library  of  enterprise-­‐grade  components,  e.g.  grids,  charts  

•  Cool  code  generator  Sencha  CMD  

•  Promotes  MVC  architecture  

•  Some  code  reuse  for  mobile  app  with  Sencha  Touch  

•  The  “weight”  of  the  app  substan?ally  increases  

•  If  you  decided  to  go  with  Ext  JS,  there  is  no  easy  way  out  

•  Doesn’t  support  Responsive  Web  Design  

•  Has  steep  learning  curve  –  has  no  HTML,  but  new  JS-­‐based  syntax  

Page 21: Seven Versions of One Web Application

Ext  JS:    index.html  and  app.js  

Page 22: Seven Versions of One Web Application

Ext  JS:    index.html  and  app.js  

Page 23: Seven Versions of One Web Application

Ext  JS  MVC  

Page 24: Seven Versions of One Web Application

Genera?ng  a  project  with  Sencha  CMD  sencha  -­‐sdk  /Library/ext-­‐4.2  generate  app  HelloWorld  /Users/yfain11/hello  

Page 25: Seven Versions of One Web Application

The  View  Fragment:  DonateForm.js    

Page 26: Seven Versions of One Web Application

V4:  Demo  with  Ext  JS  

Page 27: Seven Versions of One Web Application

V5:  Modularizing  UI  •  Large  apps  should  be  modularized  to  avoid  loading  all  code  at  once.  

•  Mul?ple  <script> tags  may  depend  on  each  other  and  have  to  

be  loaded  in  certain  order.  

•  Need  to  be  able  to  specify  dependencies  between  the  modules.  

Need  to  avoid  pollu?ng  global  scope  and  name  conflicts.    

Manually  wri?ng  Modules  doesn’t  solve  these  issues.  

•  Today:  CommonJS  and  Async  Module  Defini?on  (AMD)  specs  

•  Tomorrow:  ECMAScript  6  spec  (a.k.a.  Harmony)  defines  modules.  

Page 28: Seven Versions of One Web Application

One  way  of  implemen?ng  Module  Pakern  

Passing  inside  the  module  a  reference  to  the  global  window  object    

Page 29: Seven Versions of One Web Application

CommonJS  is  an  effort  to  standardize  JS  APIs.  

CommonJS  Modules  defines  3  variables  for  modules:                -­‐  requires          -­‐  exports          -­‐  module  Node.js  framework  implements  CommonJS  Modules  spec  and  provides  these  global  variables.  

Page 30: Seven Versions of One Web Application

Code  Sample  With  CommonJS  

Page 31: Seven Versions of One Web Application

CommonJS  Pros  and  Cons  Pros:    •  Simple  API    Cons:  •  Mainly  for  the  server-­‐side  JavaScript.  Web  browsers  don’t  have    

require,  export,  and  module  variables.      

•  The  require  method  is  synchronous.      

•  CommonJS  API  is  suitable  for  loading  JS  files,  but  can’t  load  CSS    and  HTML.  

Page 32: Seven Versions of One Web Application

Asynchronous  Module  Defini?on  (AMD)  AMD  is  a  proposal  for  async  loading  of  both  the  module  and  its  dependencies  in  Web  browsers.      You  provide  define  and  require  func?ons:    define(! module_id, // optional! [dependencies],! function (){! // This function runs once when the module and its dependencies are loaded! }!);!!!require(["main"], function() {! console.log(”The module main is loaded");!});!!

 !!!

The  func?on  define  defines  the  module  and  returns  it  once  it’s  needed.    The  require  executes  the  given  func?on  checking  that  the  dependencies  were  loaded.    

Page 33: Seven Versions of One Web Application

Save  The  Child  Modularized  With  RequireJS  

Lis?ng  modules  in  config.js  

Page 34: Seven Versions of One Web Application

V5  Demo:  With  RequireJS  

Page 35: Seven Versions of One Web Application

main.js  (fragment)  

Page 36: Seven Versions of One Web Application

“Way  To  Give”  Module  Defini?on  

Page 37: Seven Versions of One Web Application

V6:  With  jQuery  Mobile  

•  Easy  to  learn.  Built  on  top  of  jQuery  Core  library  

•  HTML5  allows  crea?ng  custom  non-­‐visible  akributes.  They  

have  to  start  with  data-:  

<div data-role="page" id="Stats">

•  The  UI  shows  one  page  at  a  ?me  

•  Light-­‐weight  (90Kb  gZipped)  

Page 38: Seven Versions of One Web Application

Mul?-­‐Page  Template  

<body> <!-- Page 1 -->

<div data-role="page" id="Donate” >

... </div>

<!-- Page 2 -->

<div data-role="page" id="Stats” >

... </div>

</body>

The  content  of  mul?ple  pages  is  located  in  one  file.    When  the  app  starts,  only  the  first  page  is  displayed  

Page 39: Seven Versions of One Web Application

Mul?-­‐Page  Template  (cont.)   <body> <!-- Page 1 -->

<div data-role="page" id="Donate">

<div data-role="header" >...</div> <div data-role="content" >...</div> <div data-role="footer" >...</div>

</div>

<!-- Page 2 -->

<div data-role="page" id="Stats"> ... </div>

</body>

Page 40: Seven Versions of One Web Application

Naviga?on  Bar   <div data-role="navbar"> <ul> <li> <a href="#Who-We-Are">Who We Are</a> </li> <li> <a href="#What-We-Do">What We Do</a> </li> <li> <a href="#Where-We-Work">Where We Work</a> </li> <li> <a href="#Way-To-Give">Way To Give</a> </li> </ul> </div>

Page 41: Seven Versions of One Web Application

Ripple  Emulator  

Page 42: Seven Versions of One Web Application

The  Back  Bukon  <div data-role="page" id="Stats" data-add-back-btn="true"> <div data-role="header" > <h1>Statistics</h1> </div> Statistics will go here </div>

Page 43: Seven Versions of One Web Application

Single-­‐Page  Template  An  HTML  file  contains  the  content  of  a  single  page.    

<div data-role="navbar"> <ul> <li> <a href="page-1.html" data-transition="slideup">Page #1</a> </li> <li> <a href="#" class="ui-state-persist">Page #2</a> </li> <li> <a href="page-3.html" data-transition="slideup">Page #3</a> </li> <li> <a href="page-4.html" data-transition="slideup">Page #4</a> </li> </ul> </div>

Page 44: Seven Versions of One Web Application

V6:  Demo  With  jQuery  Mobile  

Page 45: Seven Versions of One Web Application

V7:  With  Sencha  Touch  

•  Sencha  Touch  is  a  smaller  brother  of  Ext  JS  

•  It  comes  with  mobile  versions  of  lists,  

forms,  toolbars,  bukons,  charts,  audio,  

video,  carousel  etc.  

•  Jumpstart  development  with  genera?ng  

the  app  with  Sencha  CMD.  

•  Package  the  Sencha  Touch  app  as  na?ve  

Page 46: Seven Versions of One Web Application

The  app.JS  Ext.applica?on({          name:  'SSC',            requires:  [                  'Ext.MessageBox'          ],            views:  [                  'About',                  'CampaignsMap',                  'DonateForm',                  'DonorsChart',                  'LoginForm',                  'LoginToolbar',                  'Main',                  'Media',                  'Share',                  'ShareTile'          ],            stores:  [                  'Campaigns',                  'Countries',                  'Donors',                  'States',                  'Videos'          ],x  

         controllers:  [                  'Login'          ],            launch:  func?on()  {                  //  Destroy  the  #appLoadingIndicator  element                  Ext.fly('appLoadingIndicator').destroy();                    //  Ini?alize  the  main  view                  Ext.Viewport.add(Ext.create('SSC.view.Main'));          },            onUpdated:  func?on()  {                  Ext.Msg.confirm(                          "Applica?on  Update",                          "This  applica?on  has  just  successfully  been  updated  to  the  latest  version.  Reload  now?",                          func?on(bukonId)  {                                  if  (bukonId  ===  'yes')  {                                          window.loca?on.reload();                                  }                          }                  );          }  });  

Page 47: Seven Versions of One Web Application

The  Landing  Page  

Page 48: Seven Versions of One Web Application

Login  Controller  

Page 49: Seven Versions of One Web Application

Donors  Store  

Page 50: Seven Versions of One Web Application

jQuery  Mobile  or  Sencha  Touch?  

Use  jQuery  Mobile  if:    

•  You  are  afraid  of  being  locked  up  with  any  one  vendor.    •  You  need  your  applica?on  to  work  on  most  of  the  mobile  pla�orms.  

•  You  prefer  declara?ve  UI  and  hate  debugging  JavaScript.  

Page 51: Seven Versions of One Web Application

jQuery  Mobile  or  Sencha  Touch?  

Use  Sencha  Touch  if:    

•  You  like  to  have  a  rich  library  of  pre-­‐created  UI  •  Your  applica?on  needs  smooth  anima?on  

•  You  are  into  MVC    

•  You  want  to  package  your  applica?on  as  a  na?ve  one  •  You  want  your  applica?on  to  look  as  close  to  the  na?ve  ones    

as  possible  

Page 52: Seven Versions of One Web Application

V7:  Demo  With  Sencha  Touch  

Page 53: Seven Versions of One Web Application

Where  to  go  next?  

Google  Dart  Language:  hkps://www.dartlang.org    Google  Angular  Dart  Framework:  hkps://github.com/angular/angular.dart    

Page 54: Seven Versions of One Web Application

Links  •  7  versions  of  the  Save  The  Child  app:  hkp://savesickchild.org  

•  Enterprise  Web  Dev  book:  

hkp://oreil.ly/1hxK5hl      

•  My  employer:      

hkp://faratasystems.com    

•  My  Twiker:  @yfain