SlideShare una empresa de Scribd logo
1 de 22
Building Single-page
Applications



         HTML5 expertise at your service
About Lauri & SC5 Online
          •   ”Powerhouse for software projects”
          •   HUT graduate, Information Networks
          •   15 years in software engineering business
          •   A few startups & corporations behind
          •   Now in SC5 Online as a Software Architect

          •   Specializes in HTML5 application development
          •   Located in Helsinki (Kamppi) + Jyväskylä (Innova 2)
          •   Founded in 2006, employs 50 people
          •   Customers e.g. Sanoma, YLE, Veikkaus, F-Secure
          •   blog.sc5.io, twitter: @sc5io
Single-page Application
 A web application or web site that fits on a single web page with the
 goal of providing a more fluid user experience akin to a desktop
 application.
                                                                Wikipedia
Single-page Application
Single page apps typically have
   –   “application like” interaction
   –   dynamic data loading from the server-side API
   –   fluid transitions between page states
   –   more JavaScript than actual HTML
They typically do not have
   – support for crawlers (not for sites relying on search traffic)
   – support for legacy browsers (IE7 or older, dumbphone
     browsers)
SPAs Are Good For …
•   “App-like user experience”
•   Binding to your own (or 3rd party) RESTful API
•   Replacement for Flash or Java in your web pages
•   Hybrid (native) HTML5 applications
•   Mobile version of your web site
    The SPA sweet spot is likely not on web sites,
    but on content-rich cross-platform mobile apps
App-like User Experience




   Note: These (all) are not our work but showcases that Finns can do good stuff!
Native Apps vs. Hybrid/Mobile Web Sites
“The real problem with apps was that when people read on electronic
media, they expect the stories to possess the linky-ness of the Web—
but stories in apps didn’t really link.”

“Software development of apps was much harder than publishers had
anticipated, because they had hired Web developers who knew
technologies like HTML, CSS, and JavaScript. Publishers were
astonished to learn that iPad apps were in fact real, if
small, applications, written mostly in a language called Objective
C, which no one in their Web-dev departments knew. Publishers
responded by outsourcing app development, which was
expensive, time-consuming, and unbudgeted.”
                        Why Publishers Don't Like Apps in MIT Technology Review
SPAs and Other Web App Architectures
                        Server-side                Server-side + AJAX        PJAX                     SPA
What                    Server round-trip on       Render initial page on    Render initial page on   Serve static page
                        every app state change     server, state changes     server, state changes    skeleton from server;
                                                   on the client             on server, inject into   render every change on
                                                                             DOM on client-side       client-side
How                     UI code on server; links   UI code on both ends;     UI code on server,       UI code on client,
                        & form posting             AJAX calls, ugly server   client to inject HTTP,   server API
                                                   API                       server API if you like
Ease of development

UX & responsiveness

Robots & old browsers

Who’s using it?         Amazon, Wikipedia;         Facebook?;                Twitter, Basecamp,       Google+, Gmail, FT;
                        banks, media sites etc.    widgets, search           GitHub                   mobile sites, startups
SPA Frameworks




Need help in comparison? Try TodoMVC!
Anatomy of a Backbone SPA
              •   Application as a „singleton‟
                  reference holder
              •   Router handles the navigation and
                  toggles between views
              •   Models synchronize with Server
                  API
              •   Bulk of the code in views
              •   All HTML in templates
SPA Client-Server Communication
              •   HTML and all the assets are loaded in
                  first request
              •   Additional data is fetched over
                  XMLHTTPRequest
              •   In addition to normal server stack, you
                  need to have API endpoints in the same
                  level as presentation layer

              •   If you want to go real-time, WebSockets
                  (socket.io) can help you
              •   When it gets slow, cluster the backend
                  behind a caching reverse proxy like
                  Varnish
Sample App Stack
            App
                                          Backbone App                                                 When the app gets complex, you need modularity
    (Backbone Router)                                                                                   require.js
                                           Views                             Models
          Router                   (Backbone View)                       (Backbone Model)
    (Backbone Router)                                                                                  When the devices have differences, you need
                                                                                                       feature detection (only a few shims really work)
  modernizr
   (feature
                                                     Backbone
                                                   LayoutManager
                                                                                 Handlebars             modernizr, semantic.gs
                                                                               (template engine)
  detection)                                            (view utility)
                          DOMReady
   fastclick
   (normalise
                        (bootstrapping)                     View & Templating Stack                    When you want to have an optimized app,
click handling)
                        Underscore.js
                        (object/array
                                                                         Backbone                      variability or a native app, you need builds
                                                                                                        grunt
                                                                   (MVC framework)
                            utils)
Cross-Browser                                                              jQuery
 Compatibility            Utility Belt                                   (DOM access)

                                              RequireJS
                                         (dependency mgmt)
                                                                                                       Sample boilerplate available at SC5 GitHub
       320 and Up                                                                   Semantic.gs
        (boilerplate)                    HTML5 Foundation                           (boilerplate)


                                                                                                     Our component
    Bower                LESS            Jasmine               Grunt            Node.js & Express
(package mgmt)           (CSS)           (unit tests)         (builds)            (web/API server)   3rd party component
                                  Build, Testing & Deployment                                        Subsystems
Handling Navigation (location)
•   Browsers already have navigation controls; support them
•   HTML5 pushState exists exactly for this purpose
•   Handled by History in Backbone and $location in Angular
•   Remember fallback to hashbang „#‟ with legacy browsers
•   Remember to use URL rewrites in the server side
Handling Models (dynamic data)
•   Backbone has a flat model of Collections containing Models
•   Input validation (can block the invalid input, blocks on save())
•   Multiple view bindings (through events)
•   Custom data - model mappings (through parse())
•   Synchronizing with servers
       •   fetch() -> GET
       •   save() -> POST or PUT
       •   delete() -> DELETE
Handling Models (dynamic data)
• Can be easily extended by overriding Backbone.sync()
     •   Real-time communications (web sockets)
     •   Offline use (localStorage)
• Avoid spaghetti code:
     •   If your UI state does not fit the server schema, override parse()
         and save()
     •   Use the models as the state of your views
     •   Isolate client-server communication to models and collections
     •   If you ever plan to reuse your models, fix your schema and don‟t
         hard-code your URLs
Handling Views (DOM)
• Usually your sequence is as simple as:
   1.Update model  triggers change in views
   2.Refresh views (render)  render template  apply into DOM
   3.Notify the other views (if for some reason they cannot listen to the
     same model)
Handling Views (DOM)
• Avoid spaghetti code
      •   Backbone expects to keep Models and Views in sync
      •   A view should only alter the parts of DOM it owns
      •   A view should not call directly other views than its children
      •   Use the event binding facilities offered by framework
          (e.g. Backbone.view.events: {})
      •   A few jQuery calls to alter a subset of DOM is more code and more
          expensive than replacing the same subset by a template
 Always drive your view changes through your model
 Use events for messaging between the application parts
 Use templates; usually it is ok to render the view again
Page Rendering – Templates
• Easier way of creating a bunch of HTML elements
• Inject HTML into DOM using $.html()
• The principle is the same in server-side: call template
  with the parameters as data-object to get HTML

Samples: Handlebars, Dust.js, EJS, Google Closure
Templates
See: LinkedIn comparison of template engines
Summary
•   SPA ~ MV(C) Pattern ~ Server API driven app
•   A toolbelt of a JS framework and supplementary libraries
•   Still fairly new paradigm, not in wide use yet
•   Good complement to your existing web site
      • Mobile/Hybrid app
      • May replace your existing site when solving the crawling
        issue
Further Reading
• HTML5 sovellusalustana (a book by Pyry L & Jukka K)
  http://www.julkaisija.fi/yleista/html5.php
• Developing Backbone.js Applications (a CC book by Addy Osmani)
  https://github.com/addyosmani/backbone-fundamentals
• HTML5 Rocks as a vault of information
  http://www.html5rocks.com/en/
• A catalogue of JavaScript libraries to choose among
  http://www.jsdb.io/
Thank you !

                 Lauri Svan
                 Software Architect, SC5 Online Ltd
                 https://github.com/laurisvan
                 https://twitter.com/laurisvan




HTML5 expertise at your service

Más contenido relacionado

La actualidad más candente

Beginning MEAN Stack
Beginning MEAN StackBeginning MEAN Stack
Beginning MEAN StackRob Davarnia
 
MongoDB Days Silicon Valley: Building Applications with the MEAN Stack
MongoDB Days Silicon Valley: Building Applications with the MEAN StackMongoDB Days Silicon Valley: Building Applications with the MEAN Stack
MongoDB Days Silicon Valley: Building Applications with the MEAN StackMongoDB
 
Single Page Application presentation
Single Page Application presentationSingle Page Application presentation
Single Page Application presentationJohn Staveley
 
The Art of AngularJS in 2015
The Art of AngularJS in 2015The Art of AngularJS in 2015
The Art of AngularJS in 2015Matt Raible
 
Single Page Application Best practices
Single Page Application Best practicesSingle Page Application Best practices
Single Page Application Best practicesTarence DSouza
 
JavaScript Performance (at SFJS)
JavaScript Performance (at SFJS)JavaScript Performance (at SFJS)
JavaScript Performance (at SFJS)Steve Souders
 
AngularJS vs React JS vs Node JS: Which is Best For Web Development ?
AngularJS vs React JS vs Node JS: Which is Best For Web Development ?AngularJS vs React JS vs Node JS: Which is Best For Web Development ?
AngularJS vs React JS vs Node JS: Which is Best For Web Development ?MarkupBox
 
Node PDX: Intro to Sails.js
Node PDX: Intro to Sails.jsNode PDX: Intro to Sails.js
Node PDX: Intro to Sails.jsMike McNeil
 
MEAN Stack
MEAN StackMEAN Stack
MEAN StackDotitude
 
In Pursuit of the Holy Grail: Building Isomorphic JavaScript Apps
In Pursuit of the Holy Grail: Building Isomorphic JavaScript AppsIn Pursuit of the Holy Grail: Building Isomorphic JavaScript Apps
In Pursuit of the Holy Grail: Building Isomorphic JavaScript AppsSpike Brehm
 
The MEAN stack - SoCalCodeCamp - june 29th 2014
The MEAN stack - SoCalCodeCamp - june 29th 2014The MEAN stack - SoCalCodeCamp - june 29th 2014
The MEAN stack - SoCalCodeCamp - june 29th 2014Simona Clapan
 
Introduction To Single Page Application
Introduction To Single Page ApplicationIntroduction To Single Page Application
Introduction To Single Page ApplicationKMS Technology
 
Mvvm knockout vs angular
Mvvm knockout vs angularMvvm knockout vs angular
Mvvm knockout vs angularBasarat Syed
 
Single Page Applications on JavaScript and ASP.NET MVC4
Single Page Applications on JavaScript and ASP.NET MVC4Single Page Applications on JavaScript and ASP.NET MVC4
Single Page Applications on JavaScript and ASP.NET MVC4Yuriy Shapovalov
 
Thinking in Components
Thinking in ComponentsThinking in Components
Thinking in ComponentsFITC
 
Learn Developing REST API in Node.js using LoopBack Framework
Learn Developing REST API  in Node.js using LoopBack FrameworkLearn Developing REST API  in Node.js using LoopBack Framework
Learn Developing REST API in Node.js using LoopBack FrameworkMarudi Subakti
 

La actualidad más candente (20)

Beginning MEAN Stack
Beginning MEAN StackBeginning MEAN Stack
Beginning MEAN Stack
 
MongoDB Days Silicon Valley: Building Applications with the MEAN Stack
MongoDB Days Silicon Valley: Building Applications with the MEAN StackMongoDB Days Silicon Valley: Building Applications with the MEAN Stack
MongoDB Days Silicon Valley: Building Applications with the MEAN Stack
 
Single Page Application presentation
Single Page Application presentationSingle Page Application presentation
Single Page Application presentation
 
The Art of AngularJS in 2015
The Art of AngularJS in 2015The Art of AngularJS in 2015
The Art of AngularJS in 2015
 
Single Page Application Best practices
Single Page Application Best practicesSingle Page Application Best practices
Single Page Application Best practices
 
JavaScript Performance (at SFJS)
JavaScript Performance (at SFJS)JavaScript Performance (at SFJS)
JavaScript Performance (at SFJS)
 
AngularJS vs React JS vs Node JS: Which is Best For Web Development ?
AngularJS vs React JS vs Node JS: Which is Best For Web Development ?AngularJS vs React JS vs Node JS: Which is Best For Web Development ?
AngularJS vs React JS vs Node JS: Which is Best For Web Development ?
 
The MEAN Stack
The MEAN StackThe MEAN Stack
The MEAN Stack
 
Node PDX: Intro to Sails.js
Node PDX: Intro to Sails.jsNode PDX: Intro to Sails.js
Node PDX: Intro to Sails.js
 
MEAN Stack
MEAN Stack MEAN Stack
MEAN Stack
 
MEAN Stack
MEAN StackMEAN Stack
MEAN Stack
 
In Pursuit of the Holy Grail: Building Isomorphic JavaScript Apps
In Pursuit of the Holy Grail: Building Isomorphic JavaScript AppsIn Pursuit of the Holy Grail: Building Isomorphic JavaScript Apps
In Pursuit of the Holy Grail: Building Isomorphic JavaScript Apps
 
The MEAN stack - SoCalCodeCamp - june 29th 2014
The MEAN stack - SoCalCodeCamp - june 29th 2014The MEAN stack - SoCalCodeCamp - june 29th 2014
The MEAN stack - SoCalCodeCamp - june 29th 2014
 
Introduction To Single Page Application
Introduction To Single Page ApplicationIntroduction To Single Page Application
Introduction To Single Page Application
 
Mvvm knockout vs angular
Mvvm knockout vs angularMvvm knockout vs angular
Mvvm knockout vs angular
 
Single Page Applications on JavaScript and ASP.NET MVC4
Single Page Applications on JavaScript and ASP.NET MVC4Single Page Applications on JavaScript and ASP.NET MVC4
Single Page Applications on JavaScript and ASP.NET MVC4
 
Booting up with polymer
Booting up with polymerBooting up with polymer
Booting up with polymer
 
Thinking in Components
Thinking in ComponentsThinking in Components
Thinking in Components
 
Require js
Require jsRequire js
Require js
 
Learn Developing REST API in Node.js using LoopBack Framework
Learn Developing REST API  in Node.js using LoopBack FrameworkLearn Developing REST API  in Node.js using LoopBack Framework
Learn Developing REST API in Node.js using LoopBack Framework
 

Destacado

Creating Powerful Customer Experiences
Creating Powerful Customer ExperiencesCreating Powerful Customer Experiences
Creating Powerful Customer ExperiencesDigital Surgeons
 
How to Craft Your Company's Storytelling Voice by Ann Handley of MarketingProfs
How to Craft Your Company's Storytelling Voice by Ann Handley of MarketingProfsHow to Craft Your Company's Storytelling Voice by Ann Handley of MarketingProfs
How to Craft Your Company's Storytelling Voice by Ann Handley of MarketingProfsMarketingProfs
 
What REALLY Differentiates The Best Content Marketers From The Rest
What REALLY Differentiates The Best Content Marketers From The RestWhat REALLY Differentiates The Best Content Marketers From The Rest
What REALLY Differentiates The Best Content Marketers From The RestRoss Simmonds
 
20 Tweetable Quotes to Inspire Marketing & Design Creative Genius
20 Tweetable Quotes to Inspire Marketing & Design Creative Genius20 Tweetable Quotes to Inspire Marketing & Design Creative Genius
20 Tweetable Quotes to Inspire Marketing & Design Creative GeniusIMPACT Branding & Design LLC
 
40 Tools in 20 Minutes: Hacking your Marketing Career
40 Tools in 20 Minutes: Hacking your Marketing Career40 Tools in 20 Minutes: Hacking your Marketing Career
40 Tools in 20 Minutes: Hacking your Marketing CareerEric Leist
 
Digital transformation in 50 soundbites
Digital transformation in 50 soundbitesDigital transformation in 50 soundbites
Digital transformation in 50 soundbitesJulie Dodd
 
Eco-nomics, The hidden costs of consumption
Eco-nomics, The hidden costs of consumptionEco-nomics, The hidden costs of consumption
Eco-nomics, The hidden costs of consumptionJosh Beatty
 
6 Snapchat Hacks Too Easy To Ignore
6 Snapchat Hacks Too Easy To Ignore6 Snapchat Hacks Too Easy To Ignore
6 Snapchat Hacks Too Easy To IgnoreGary Vaynerchuk
 
All About Beer
All About Beer All About Beer
All About Beer Ethos3
 
Healthcare Napkins All
Healthcare Napkins AllHealthcare Napkins All
Healthcare Napkins AllDan Roam
 
SMOKE - The Convenient Truth [1st place Worlds Best Presentation Contest] by ...
SMOKE - The Convenient Truth [1st place Worlds Best Presentation Contest] by ...SMOKE - The Convenient Truth [1st place Worlds Best Presentation Contest] by ...
SMOKE - The Convenient Truth [1st place Worlds Best Presentation Contest] by ...Empowered Presentations
 
Pixar's 22 Rules to Phenomenal Storytelling
Pixar's 22 Rules to Phenomenal StorytellingPixar's 22 Rules to Phenomenal Storytelling
Pixar's 22 Rules to Phenomenal StorytellingGavin McMahon
 
The Search for Meaning in B2B Marketing
The Search for Meaning in B2B MarketingThe Search for Meaning in B2B Marketing
The Search for Meaning in B2B MarketingVelocity Partners
 
10 Powerful Body Language Tips for your next Presentation
10 Powerful Body Language Tips for your next Presentation10 Powerful Body Language Tips for your next Presentation
10 Powerful Body Language Tips for your next PresentationSOAP Presentations
 

Destacado (19)

Creating Powerful Customer Experiences
Creating Powerful Customer ExperiencesCreating Powerful Customer Experiences
Creating Powerful Customer Experiences
 
How to Craft Your Company's Storytelling Voice by Ann Handley of MarketingProfs
How to Craft Your Company's Storytelling Voice by Ann Handley of MarketingProfsHow to Craft Your Company's Storytelling Voice by Ann Handley of MarketingProfs
How to Craft Your Company's Storytelling Voice by Ann Handley of MarketingProfs
 
What REALLY Differentiates The Best Content Marketers From The Rest
What REALLY Differentiates The Best Content Marketers From The RestWhat REALLY Differentiates The Best Content Marketers From The Rest
What REALLY Differentiates The Best Content Marketers From The Rest
 
20 Tweetable Quotes to Inspire Marketing & Design Creative Genius
20 Tweetable Quotes to Inspire Marketing & Design Creative Genius20 Tweetable Quotes to Inspire Marketing & Design Creative Genius
20 Tweetable Quotes to Inspire Marketing & Design Creative Genius
 
40 Tools in 20 Minutes: Hacking your Marketing Career
40 Tools in 20 Minutes: Hacking your Marketing Career40 Tools in 20 Minutes: Hacking your Marketing Career
40 Tools in 20 Minutes: Hacking your Marketing Career
 
2015 Travel Trends
2015 Travel Trends 2015 Travel Trends
2015 Travel Trends
 
Digital transformation in 50 soundbites
Digital transformation in 50 soundbitesDigital transformation in 50 soundbites
Digital transformation in 50 soundbites
 
Build a Better Entrepreneur Pitch Deck
Build a Better Entrepreneur Pitch DeckBuild a Better Entrepreneur Pitch Deck
Build a Better Entrepreneur Pitch Deck
 
Digital, Social & Mobile in 2015
Digital, Social & Mobile in 2015Digital, Social & Mobile in 2015
Digital, Social & Mobile in 2015
 
Eco-nomics, The hidden costs of consumption
Eco-nomics, The hidden costs of consumptionEco-nomics, The hidden costs of consumption
Eco-nomics, The hidden costs of consumption
 
6 Snapchat Hacks Too Easy To Ignore
6 Snapchat Hacks Too Easy To Ignore6 Snapchat Hacks Too Easy To Ignore
6 Snapchat Hacks Too Easy To Ignore
 
All About Beer
All About Beer All About Beer
All About Beer
 
Healthcare Napkins All
Healthcare Napkins AllHealthcare Napkins All
Healthcare Napkins All
 
SMOKE - The Convenient Truth [1st place Worlds Best Presentation Contest] by ...
SMOKE - The Convenient Truth [1st place Worlds Best Presentation Contest] by ...SMOKE - The Convenient Truth [1st place Worlds Best Presentation Contest] by ...
SMOKE - The Convenient Truth [1st place Worlds Best Presentation Contest] by ...
 
Pixar's 22 Rules to Phenomenal Storytelling
Pixar's 22 Rules to Phenomenal StorytellingPixar's 22 Rules to Phenomenal Storytelling
Pixar's 22 Rules to Phenomenal Storytelling
 
You Suck At PowerPoint! by @jessedee
You Suck At PowerPoint! by @jessedeeYou Suck At PowerPoint! by @jessedee
You Suck At PowerPoint! by @jessedee
 
The Search for Meaning in B2B Marketing
The Search for Meaning in B2B MarketingThe Search for Meaning in B2B Marketing
The Search for Meaning in B2B Marketing
 
How Google Works
How Google WorksHow Google Works
How Google Works
 
10 Powerful Body Language Tips for your next Presentation
10 Powerful Body Language Tips for your next Presentation10 Powerful Body Language Tips for your next Presentation
10 Powerful Body Language Tips for your next Presentation
 

Similar a Building single page applications

Angular jS Introduction by Google
Angular jS Introduction by GoogleAngular jS Introduction by Google
Angular jS Introduction by GoogleASG
 
Real-world Dojo Mobile
Real-world Dojo MobileReal-world Dojo Mobile
Real-world Dojo MobileAndrew Ferrier
 
NoSql presentation
NoSql presentationNoSql presentation
NoSql presentationMat Wall
 
Modern Architectures with Spring and JavaScript
Modern Architectures with Spring and JavaScriptModern Architectures with Spring and JavaScript
Modern Architectures with Spring and JavaScriptmartinlippert
 
No SQL at The Guardian
No SQL at The GuardianNo SQL at The Guardian
No SQL at The GuardianMat Wall
 
전문가토크릴레이 1탄 html5 전망 (전종홍 박사)
전문가토크릴레이 1탄 html5 전망 (전종홍 박사)전문가토크릴레이 1탄 html5 전망 (전종홍 박사)
전문가토크릴레이 1탄 html5 전망 (전종홍 박사)Saltlux zinyus
 
전문가 토크릴레이 1탄 html5 전망 (전종홍 박사)
전문가 토크릴레이 1탄 html5 전망 (전종홍 박사)전문가 토크릴레이 1탄 html5 전망 (전종홍 박사)
전문가 토크릴레이 1탄 html5 전망 (전종홍 박사)zinyus
 
2013 04-02-server-side-backbone
2013 04-02-server-side-backbone2013 04-02-server-side-backbone
2013 04-02-server-side-backboneSC5.io
 
AJAX Frameworks
AJAX FrameworksAJAX Frameworks
AJAX Frameworksshank
 
HTML5 and the dawn of rich mobile web applications
HTML5 and the dawn of rich mobile web applicationsHTML5 and the dawn of rich mobile web applications
HTML5 and the dawn of rich mobile web applicationsJames Pearce
 
Inaugural address manjusha - Indicthreads cloud computing conference 2011
Inaugural address manjusha -  Indicthreads cloud computing conference 2011Inaugural address manjusha -  Indicthreads cloud computing conference 2011
Inaugural address manjusha - Indicthreads cloud computing conference 2011IndicThreads
 
HTML5 and the dawn of rich mobile web applications pt 1
HTML5 and the dawn of rich mobile web applications pt 1HTML5 and the dawn of rich mobile web applications pt 1
HTML5 and the dawn of rich mobile web applications pt 1James Pearce
 
Modern Architectures with Spring and JavaScript
Modern Architectures with Spring and JavaScriptModern Architectures with Spring and JavaScript
Modern Architectures with Spring and JavaScriptmartinlippert
 
JAX 2012: Moderne Architektur mit Spring und JavaScript
JAX 2012: Moderne Architektur mit Spring und JavaScriptJAX 2012: Moderne Architektur mit Spring und JavaScript
JAX 2012: Moderne Architektur mit Spring und JavaScriptmartinlippert
 
Seven Versions of One Web Application
Seven Versions of One Web ApplicationSeven Versions of One Web Application
Seven Versions of One Web ApplicationYakov Fain
 
Effectively using Nokia Web Tools 2.0 templates for Series 40 web apps
Effectively using Nokia Web Tools 2.0 templates for Series 40 web appsEffectively using Nokia Web Tools 2.0 templates for Series 40 web apps
Effectively using Nokia Web Tools 2.0 templates for Series 40 web appsMicrosoft Mobile Developer
 
S60 3rd FP2 Widgets
S60 3rd FP2 WidgetsS60 3rd FP2 Widgets
S60 3rd FP2 Widgetsromek
 
baidu开发者大会 - Web App开发框架介绍以及分析
baidu开发者大会 - Web App开发框架介绍以及分析baidu开发者大会 - Web App开发框架介绍以及分析
baidu开发者大会 - Web App开发框架介绍以及分析joylite
 

Similar a Building single page applications (20)

Angular jS Introduction by Google
Angular jS Introduction by GoogleAngular jS Introduction by Google
Angular jS Introduction by Google
 
20120306 dublin js
20120306 dublin js20120306 dublin js
20120306 dublin js
 
Real-world Dojo Mobile
Real-world Dojo MobileReal-world Dojo Mobile
Real-world Dojo Mobile
 
NoSql presentation
NoSql presentationNoSql presentation
NoSql presentation
 
Modern Architectures with Spring and JavaScript
Modern Architectures with Spring and JavaScriptModern Architectures with Spring and JavaScript
Modern Architectures with Spring and JavaScript
 
No SQL at The Guardian
No SQL at The GuardianNo SQL at The Guardian
No SQL at The Guardian
 
전문가토크릴레이 1탄 html5 전망 (전종홍 박사)
전문가토크릴레이 1탄 html5 전망 (전종홍 박사)전문가토크릴레이 1탄 html5 전망 (전종홍 박사)
전문가토크릴레이 1탄 html5 전망 (전종홍 박사)
 
전문가 토크릴레이 1탄 html5 전망 (전종홍 박사)
전문가 토크릴레이 1탄 html5 전망 (전종홍 박사)전문가 토크릴레이 1탄 html5 전망 (전종홍 박사)
전문가 토크릴레이 1탄 html5 전망 (전종홍 박사)
 
2013 04-02-server-side-backbone
2013 04-02-server-side-backbone2013 04-02-server-side-backbone
2013 04-02-server-side-backbone
 
AJAX Frameworks
AJAX FrameworksAJAX Frameworks
AJAX Frameworks
 
HTML5 and the dawn of rich mobile web applications
HTML5 and the dawn of rich mobile web applicationsHTML5 and the dawn of rich mobile web applications
HTML5 and the dawn of rich mobile web applications
 
Inaugural address manjusha - Indicthreads cloud computing conference 2011
Inaugural address manjusha -  Indicthreads cloud computing conference 2011Inaugural address manjusha -  Indicthreads cloud computing conference 2011
Inaugural address manjusha - Indicthreads cloud computing conference 2011
 
HTML5 and the dawn of rich mobile web applications pt 1
HTML5 and the dawn of rich mobile web applications pt 1HTML5 and the dawn of rich mobile web applications pt 1
HTML5 and the dawn of rich mobile web applications pt 1
 
Modern Architectures with Spring and JavaScript
Modern Architectures with Spring and JavaScriptModern Architectures with Spring and JavaScript
Modern Architectures with Spring and JavaScript
 
20120802 timisoara
20120802 timisoara20120802 timisoara
20120802 timisoara
 
JAX 2012: Moderne Architektur mit Spring und JavaScript
JAX 2012: Moderne Architektur mit Spring und JavaScriptJAX 2012: Moderne Architektur mit Spring und JavaScript
JAX 2012: Moderne Architektur mit Spring und JavaScript
 
Seven Versions of One Web Application
Seven Versions of One Web ApplicationSeven Versions of One Web Application
Seven Versions of One Web Application
 
Effectively using Nokia Web Tools 2.0 templates for Series 40 web apps
Effectively using Nokia Web Tools 2.0 templates for Series 40 web appsEffectively using Nokia Web Tools 2.0 templates for Series 40 web apps
Effectively using Nokia Web Tools 2.0 templates for Series 40 web apps
 
S60 3rd FP2 Widgets
S60 3rd FP2 WidgetsS60 3rd FP2 Widgets
S60 3rd FP2 Widgets
 
baidu开发者大会 - Web App开发框架介绍以及分析
baidu开发者大会 - Web App开发框架介绍以及分析baidu开发者大会 - Web App开发框架介绍以及分析
baidu开发者大会 - Web App开发框架介绍以及分析
 

Más de SC5.io

AWS Machine Learning & Google Cloud Machine Learning
AWS Machine Learning & Google Cloud Machine LearningAWS Machine Learning & Google Cloud Machine Learning
AWS Machine Learning & Google Cloud Machine LearningSC5.io
 
Transfer learning with Custom Vision
Transfer learning with Custom VisionTransfer learning with Custom Vision
Transfer learning with Custom VisionSC5.io
 
Practical AI for Business: Bandit Algorithms
Practical AI for Business: Bandit AlgorithmsPractical AI for Business: Bandit Algorithms
Practical AI for Business: Bandit AlgorithmsSC5.io
 
Decision trees & random forests
Decision trees & random forestsDecision trees & random forests
Decision trees & random forestsSC5.io
 
Bandit Algorithms
Bandit AlgorithmsBandit Algorithms
Bandit AlgorithmsSC5.io
 
Machine Learning Using Cloud Services
Machine Learning Using Cloud ServicesMachine Learning Using Cloud Services
Machine Learning Using Cloud ServicesSC5.io
 
Angular.js Primer in Aalto University
Angular.js Primer in Aalto UniversityAngular.js Primer in Aalto University
Angular.js Primer in Aalto UniversitySC5.io
 
Miten design-muutosjohtaminen hyödyttää yrityksiä?
Miten design-muutosjohtaminen hyödyttää yrityksiä?Miten design-muutosjohtaminen hyödyttää yrityksiä?
Miten design-muutosjohtaminen hyödyttää yrityksiä?SC5.io
 
Securing the client side web
Securing the client side webSecuring the client side web
Securing the client side webSC5.io
 
Engineering HTML5 Applications for Better Performance
Engineering HTML5 Applications for Better PerformanceEngineering HTML5 Applications for Better Performance
Engineering HTML5 Applications for Better PerformanceSC5.io
 
2013 10-02-backbone-robots-aarhus
2013 10-02-backbone-robots-aarhus2013 10-02-backbone-robots-aarhus
2013 10-02-backbone-robots-aarhusSC5.io
 
2013 10-02-html5-performance-aarhus
2013 10-02-html5-performance-aarhus2013 10-02-html5-performance-aarhus
2013 10-02-html5-performance-aarhusSC5.io
 

Más de SC5.io (12)

AWS Machine Learning & Google Cloud Machine Learning
AWS Machine Learning & Google Cloud Machine LearningAWS Machine Learning & Google Cloud Machine Learning
AWS Machine Learning & Google Cloud Machine Learning
 
Transfer learning with Custom Vision
Transfer learning with Custom VisionTransfer learning with Custom Vision
Transfer learning with Custom Vision
 
Practical AI for Business: Bandit Algorithms
Practical AI for Business: Bandit AlgorithmsPractical AI for Business: Bandit Algorithms
Practical AI for Business: Bandit Algorithms
 
Decision trees & random forests
Decision trees & random forestsDecision trees & random forests
Decision trees & random forests
 
Bandit Algorithms
Bandit AlgorithmsBandit Algorithms
Bandit Algorithms
 
Machine Learning Using Cloud Services
Machine Learning Using Cloud ServicesMachine Learning Using Cloud Services
Machine Learning Using Cloud Services
 
Angular.js Primer in Aalto University
Angular.js Primer in Aalto UniversityAngular.js Primer in Aalto University
Angular.js Primer in Aalto University
 
Miten design-muutosjohtaminen hyödyttää yrityksiä?
Miten design-muutosjohtaminen hyödyttää yrityksiä?Miten design-muutosjohtaminen hyödyttää yrityksiä?
Miten design-muutosjohtaminen hyödyttää yrityksiä?
 
Securing the client side web
Securing the client side webSecuring the client side web
Securing the client side web
 
Engineering HTML5 Applications for Better Performance
Engineering HTML5 Applications for Better PerformanceEngineering HTML5 Applications for Better Performance
Engineering HTML5 Applications for Better Performance
 
2013 10-02-backbone-robots-aarhus
2013 10-02-backbone-robots-aarhus2013 10-02-backbone-robots-aarhus
2013 10-02-backbone-robots-aarhus
 
2013 10-02-html5-performance-aarhus
2013 10-02-html5-performance-aarhus2013 10-02-html5-performance-aarhus
2013 10-02-html5-performance-aarhus
 

Último

Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 

Último (20)

Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 

Building single page applications

  • 1. Building Single-page Applications HTML5 expertise at your service
  • 2. About Lauri & SC5 Online • ”Powerhouse for software projects” • HUT graduate, Information Networks • 15 years in software engineering business • A few startups & corporations behind • Now in SC5 Online as a Software Architect • Specializes in HTML5 application development • Located in Helsinki (Kamppi) + Jyväskylä (Innova 2) • Founded in 2006, employs 50 people • Customers e.g. Sanoma, YLE, Veikkaus, F-Secure • blog.sc5.io, twitter: @sc5io
  • 3. Single-page Application A web application or web site that fits on a single web page with the goal of providing a more fluid user experience akin to a desktop application. Wikipedia
  • 4.
  • 5. Single-page Application Single page apps typically have – “application like” interaction – dynamic data loading from the server-side API – fluid transitions between page states – more JavaScript than actual HTML They typically do not have – support for crawlers (not for sites relying on search traffic) – support for legacy browsers (IE7 or older, dumbphone browsers)
  • 6. SPAs Are Good For … • “App-like user experience” • Binding to your own (or 3rd party) RESTful API • Replacement for Flash or Java in your web pages • Hybrid (native) HTML5 applications • Mobile version of your web site The SPA sweet spot is likely not on web sites, but on content-rich cross-platform mobile apps
  • 7. App-like User Experience Note: These (all) are not our work but showcases that Finns can do good stuff!
  • 8. Native Apps vs. Hybrid/Mobile Web Sites “The real problem with apps was that when people read on electronic media, they expect the stories to possess the linky-ness of the Web— but stories in apps didn’t really link.” “Software development of apps was much harder than publishers had anticipated, because they had hired Web developers who knew technologies like HTML, CSS, and JavaScript. Publishers were astonished to learn that iPad apps were in fact real, if small, applications, written mostly in a language called Objective C, which no one in their Web-dev departments knew. Publishers responded by outsourcing app development, which was expensive, time-consuming, and unbudgeted.” Why Publishers Don't Like Apps in MIT Technology Review
  • 9. SPAs and Other Web App Architectures Server-side Server-side + AJAX PJAX SPA What Server round-trip on Render initial page on Render initial page on Serve static page every app state change server, state changes server, state changes skeleton from server; on the client on server, inject into render every change on DOM on client-side client-side How UI code on server; links UI code on both ends; UI code on server, UI code on client, & form posting AJAX calls, ugly server client to inject HTTP, server API API server API if you like Ease of development UX & responsiveness Robots & old browsers Who’s using it? Amazon, Wikipedia; Facebook?; Twitter, Basecamp, Google+, Gmail, FT; banks, media sites etc. widgets, search GitHub mobile sites, startups
  • 10. SPA Frameworks Need help in comparison? Try TodoMVC!
  • 11. Anatomy of a Backbone SPA • Application as a „singleton‟ reference holder • Router handles the navigation and toggles between views • Models synchronize with Server API • Bulk of the code in views • All HTML in templates
  • 12. SPA Client-Server Communication • HTML and all the assets are loaded in first request • Additional data is fetched over XMLHTTPRequest • In addition to normal server stack, you need to have API endpoints in the same level as presentation layer • If you want to go real-time, WebSockets (socket.io) can help you • When it gets slow, cluster the backend behind a caching reverse proxy like Varnish
  • 13. Sample App Stack App Backbone App When the app gets complex, you need modularity (Backbone Router)  require.js Views Models Router (Backbone View) (Backbone Model) (Backbone Router) When the devices have differences, you need feature detection (only a few shims really work) modernizr (feature Backbone LayoutManager Handlebars  modernizr, semantic.gs (template engine) detection) (view utility) DOMReady fastclick (normalise (bootstrapping) View & Templating Stack When you want to have an optimized app, click handling) Underscore.js (object/array Backbone variability or a native app, you need builds  grunt (MVC framework) utils) Cross-Browser jQuery Compatibility Utility Belt (DOM access) RequireJS (dependency mgmt) Sample boilerplate available at SC5 GitHub 320 and Up Semantic.gs (boilerplate) HTML5 Foundation (boilerplate) Our component Bower LESS Jasmine Grunt Node.js & Express (package mgmt) (CSS) (unit tests) (builds) (web/API server) 3rd party component Build, Testing & Deployment Subsystems
  • 14. Handling Navigation (location) • Browsers already have navigation controls; support them • HTML5 pushState exists exactly for this purpose • Handled by History in Backbone and $location in Angular • Remember fallback to hashbang „#‟ with legacy browsers • Remember to use URL rewrites in the server side
  • 15. Handling Models (dynamic data) • Backbone has a flat model of Collections containing Models • Input validation (can block the invalid input, blocks on save()) • Multiple view bindings (through events) • Custom data - model mappings (through parse()) • Synchronizing with servers • fetch() -> GET • save() -> POST or PUT • delete() -> DELETE
  • 16. Handling Models (dynamic data) • Can be easily extended by overriding Backbone.sync() • Real-time communications (web sockets) • Offline use (localStorage) • Avoid spaghetti code: • If your UI state does not fit the server schema, override parse() and save() • Use the models as the state of your views • Isolate client-server communication to models and collections • If you ever plan to reuse your models, fix your schema and don‟t hard-code your URLs
  • 17. Handling Views (DOM) • Usually your sequence is as simple as: 1.Update model  triggers change in views 2.Refresh views (render)  render template  apply into DOM 3.Notify the other views (if for some reason they cannot listen to the same model)
  • 18. Handling Views (DOM) • Avoid spaghetti code • Backbone expects to keep Models and Views in sync • A view should only alter the parts of DOM it owns • A view should not call directly other views than its children • Use the event binding facilities offered by framework (e.g. Backbone.view.events: {}) • A few jQuery calls to alter a subset of DOM is more code and more expensive than replacing the same subset by a template  Always drive your view changes through your model  Use events for messaging between the application parts  Use templates; usually it is ok to render the view again
  • 19. Page Rendering – Templates • Easier way of creating a bunch of HTML elements • Inject HTML into DOM using $.html() • The principle is the same in server-side: call template with the parameters as data-object to get HTML Samples: Handlebars, Dust.js, EJS, Google Closure Templates See: LinkedIn comparison of template engines
  • 20. Summary • SPA ~ MV(C) Pattern ~ Server API driven app • A toolbelt of a JS framework and supplementary libraries • Still fairly new paradigm, not in wide use yet • Good complement to your existing web site • Mobile/Hybrid app • May replace your existing site when solving the crawling issue
  • 21. Further Reading • HTML5 sovellusalustana (a book by Pyry L & Jukka K) http://www.julkaisija.fi/yleista/html5.php • Developing Backbone.js Applications (a CC book by Addy Osmani) https://github.com/addyosmani/backbone-fundamentals • HTML5 Rocks as a vault of information http://www.html5rocks.com/en/ • A catalogue of JavaScript libraries to choose among http://www.jsdb.io/
  • 22. Thank you ! Lauri Svan Software Architect, SC5 Online Ltd https://github.com/laurisvan https://twitter.com/laurisvan HTML5 expertise at your service

Notas del editor

  1. Please keep your eye on notes – some slides contain a lot of good extra insight!
  2. “App-like user experience”Touch navigationInstant response to your clicksFluid transitions between pagesCached & pre-fetched contentBinding to your own (or 3rd party) RESTful APIEase of populating modelsReplacement for Flash or Java in your web pagese.g. FlipBoard, LinkedIn iPadHybrid (native) HTML5 applicationse.g. FlipBoard, LinkedIn iPadApache Cordova, Embedded WebViews, Tizen, Windows 8Mobile version of your web sitem.veikkaus.fi, plus.hbl.fi, app.ft.com
  3. Note: Ease of development = (design, implementation, testing, maintenance)Testing and maintenance are the hard partsServer-sideThe good old way; write that server-side templateDevelopment: There are dozens of FWs for every major language for thisHow to deal with user state? Store on cookie; Store on session  memory  clustering?Selenium will test your site alrightUX: How to get that app-like experience with 500ms clicks? Transitions? Animations?Robots: No problem if you usecanonicalurls & pagesthemselvesdon’trequireuserstateServer-side + AJAXDevelopment: The problem is in transmitting the UI state & synchronize it in both ends;The simple test: Click refresh on an AJAX page – did you get what you expected?How did you plan to test your system after all? What does your API look like?Spaghetti architectureUX: Can be made fast & responsive, but it’s tedious.Robots: If you’ve got even a single bit that is rendered on client side only, I’m sorry.PJAXDevelopment: The concept is very simple but I’m not aware of any widely used, ready-made frameworks for itBold attempts: https://github.com/defunkt/jquery-pjax, https://github.com/rails/turbolinksNo idea on how to automate testing on itUX: The pages can be pretty fast, but likely the future states are not anticipated & cacheable (like in SPAs)Robots: Twitter actually did SPA before and moved back to PJAX (I believe they missed the searchability too much)SPADevelopment: Clean model (most of the FWs use MVC model, and the future content can be fetched within model without affecting the current view)Usually server-side API is RESTful & clean and hence can be tested easily; testing the client UI is a bit so-soUX: Can have all the bells and whistlesRobots & old browsers: Test for Google (likely won’t work), other crawlers won’t work; IE7/8 and feature phone browsers will cause headacheSPA is not always the only choice, there are reasons for other choices, tooWhy Twitter went back SPA to PJAX:http://engineering.twitter.com/2012/05/improving-performance-on-twittercom.html
  4. In the end, all of the frameworks do the same thing. There is no need to switch between them on-project basis (learning always takes some time)Backbone: Simple MVC model, only ~ 800 LOC. Your grandmother would get it. No data bindings built in.Angular.js: “What DOM should have been”. Sophisticated data binding with DOM and your JavaScript model.Knockout: One of the earliest frameworks. Data binding with some enforcements on your coding styleEmber: The biggest framework (by LOC). Very object-oriented (you will drift away from DOM)
  5. Utility toolbelts:jQuery: The de-facto DOM manipulation libraryUnderscore.js: Object and Array manipulationClient-side templating engines:Handlebars: Simple templating language that does not break HTMLDust.js: Feature-rich templating language (partials, streaming etc.)ModularizationRequire.js: Module framework for JavaScriptLESS and SASS: Stylesheet languages done rightBrowser compatibilityModernizr: HTML5 and CSS3 feature detectionUI Widget FrameworksBootstrap: Customizable UI widgetsjQuery Mobile: ThemableiOS like widgets for mobile UisBuilding & Test AutomationGrunt: JavaScript/Node.js based build systemJasmine: Behavior-driven test framework; works for TDD-style processQUnit: JavaScript unit testing framework developed by jQuery communityServer APIs made easy:Node.js: JavaScript server-side stack; great for quick no nonsense API servers;express.js: Web application framework for Node.jsApplication BoilerplatesYeoman: An ambitious, grunt-based boilerplate creation utility servers;Backbone boilerplate: Simple creation of Backbone based appsHTML Boilerplates & CSS Grids320andup: Responsive boilerplate with special emphasis on mobileHTML5 Boilerplate: The classic HTML5 app structureSemantic.gs: Easy an customizable CSS grid systemPackaging into a native app:Apache Cordova: ex. PhoneGap; packaging as a hybrid app for multi-platform
  6. Browser controls:Back/ForwardReloadBookmarkingSome samples on handling URL rewriteshttp://www.josscrowcroft.com/2012/code/htaccess-for-html5-history-pushstate-url-routing/
  7. In most of the cases the flat model is ok, because you don’t want to display multiple levels of hierarchy in a single page/viewYou can extend Backbone to support deeper structures, you will need it if you want to avoid making multiple server queriesIf your structure is static, your Collection can nest other Collections as children (AFAIK Collections can’t have Collections in place of Models)You need to write a custom parse() that will notify your child collections abIt’s complicated…Backbone has a fundamental flaw in blocking input validation:In most of the cases, the user input (e.g. for text) is invalid; Backbone blocks that. The workaround is to
  8. For better real-time communications support, see socket.io
  9. When using Angular, you don’t need to do a single thing to map your model changes back to DOM
  10. Note: In most of the cases you would just want to re-render the view (unless it owns the whole DOM) for changing the state in the UI.Exception cases:You have an input form and you don’t want to lose focusYour DOM subset is huge (e.g. a whole list of a few hundred items)Some highly interactive things like sliders
  11. Each template engine works the same wayCompile the template into JavaScript function  JavaScript functionCall with parameters  HTML stringApply the string into DOM -> DOM elementsAngular is different in this regard, as the “templates” are readily as part of DOM and the manipulation happens on DOM level, not HTML levelIn basic use, comparing engines is almost pointless - pick one and stick to itSome things you might want to look for if you have a fancy application & complex templatesLocalisationTemplate inheritance (when you have a lot of redundant pages)Streaming (especially if you use the same template engine on server-side)