SlideShare a Scribd company logo
Gran Sasso Science Institute | University of L’Aquila
Ivano Malavolta
HTML5: the new frontier of the web
About me…
Ivano Malavolta

Post Doc researcher – Gran Sasso Science Institute
www.ivanomalavolta.com
Roadmap
Anatomy of a web app
Debugging (mobile) web apps
HTML5
Maintainable web apps
Roadmap
Anatomy of a web app
What is a Web App?
A software built with web technologies that is accessible via a mobile browser


The browser may be either 
the standard device browser 
or an embedded browser 
(Hybrid app)
Anatomy of a Web App
Setting up the Server



As usual, it all starts with an HTTP request
Then you need:
•  Data
•  A device detection mechanism [optional]
•  The app itself
Data 
Usually mobile apps do not talk directly with the database

à do not even think about JDBC, drivers, etc!
Ć ļƒ ā€Æ They pass through an application server and communicate via:
•  standard HTTP requests for HTML content (eg PHP)
•  REST-full services (XML, JSON, etc.)
•  SOAP
Data
•  Data can be stored in any classical way:
•  Relational
•  Graph
•  Key-value
•  Document-based

Latest trend à backend-as-a-service
BaaS
1.  Developers build a visual model of their DB

2.  The service generates APIs and client-side
libraries(compatible with Android, Windows
Phone, etc.)
3.  The data produced/consumed in the app can be
pushed/pulled to their DB
•  Communication is handled via REST-based
APIs
Example of Baas software: BaasBox
Main features:
•  User management 
•  ACL
•  Friendships
•  Authentication via Facebook and Google+
•  Document-based data manegement (via OrientDB)
•  Assets management (fotos, documents, or files)
•  Push notifications
The ā€œBoxā€ in BaasBox means that all the features are
in a standalone server, just like a box. 

No Application Server, no Database Server, just a
JVM and nothing more
Rest API
Web
dashboard
http://www.baasbox.com/
Ok, but what about mobile apps?
BROWSER


<html>
<head>
<script src=ā€ ...ā€ />
</head>
<body>
...
NATIVE
WRAPPER

<html>
<head>
<script src=ā€ ...ā€ />
</head>
<body>
...
PLATFORM APIs	

NATIVE 
APP

01010101010101101010
1010101011011010
010101010101011101
010101010101011010




PLATFORM APIs	

Native
 Web
 Hybrid
Native
http://bit.ly/GWOaP1
PRO
•  Lets you create apps with rich user interfaces and/or heavy graphics

CONS
•  Development Time
•  Development Cost
•  Ongoing Maintenance
•  No portability (apps cannot be used on other platforms)
PRO
CONS
Examples of native apps
http://www.ea.com/it/ipad/nfs 
http://www.whatsapp.com/
Web
http://bit.ly/GWOaP1
PRO
•  Offers fast development, simple maintenance, and full application portability
•  One mobile web app works on any platform

CONS
•  Can’t handle heavy graphics
•  Can’t access camera or push notifications
PRO
CONS
Examples of web apps
http://asidemag.com
http://amazon.com
Hybrid
http://bit.ly/GWOaP1
PRO
•  Development speed of mobile web apps 
•  Device access and app store distribution of native apps

CONS
•  Can’t handle heavy graphics
•  Requires familiarity with a mobile framework
PRO
CONS
Examples of hybrid apps
http://www.gmail.com
http://flipboard.com
Frascati Scienza
QR code scanning	

In-app RSS feed reader	

Maps	

Non-linear layouts	

https://itunes.apple.com/it/app/frascati-scienza-scienziati/id686974321?mt=8
Comparison
My vision
Mobile web seems to be the only long-term commercially viable platform for mobile

FRAGMENTATION
THE WEB
USER EXPECTATIONS
When you go native there are too many platforms to be supported


FRAGMENTATION
The web is the only platform that:
•  works across devices
•  apps share the same set of standards
•  the same app can work also on a desktop
THE WEB
The web is an advanced technology:
•  webGL
•  Local storage management
•  Positioning & mapping
•  Real-time data
•  ...
Users expect things to just work

à they don’t care about what platform they have
àthey simply expect that your app will be available for their device 




à YOU HAVE TO BE CROSS-PLATFORM
USER EXPECTATIONS
PhoneGap
You develop your app using the usual three guys




You use the same web view of the native OS
•  iOS = UIWebView
•  Android = android.webkit.WebView

http://phonegap.com/blog/2013/06/20/coming-soon-phonegap30
What is PhoneGap?
The UI layer is a web browser view
•  100% width
•  100% height

Headless web browser
•  No URL bar
•  No decorations
•  No zooming
•  No text selection
It looks very similar to Apache Cordova…
Adobe/Nitobi donated the PhoneGap codebase to the Apache foundation
à 
wider audience and contributors
à 
transparent governance


Better documentation
à 
easier contributions for companies


Apache Licensing
There was only one problem....


trademark ambiguity 

à CORDOVA
PhoneGap is a distribution of
Apache Cordova
Roadmap
Anatomy of a web app
 HTML5
HTML 5
HTML5 will be the new standard for HTML

HTML5 is still a work in progress

W3C final recomendation: 2020

Top browsers support many (not all) of the new HTML5 elements
http://mobilehtml5.org
http://caniuse.com
What is HTML5?
HTML5
Markup
 JavaScript
CSS3
Multimedia
The minimal HTML5 page
<!DOCTYPE	
 Ā html>	
 Ā 
<html>	
 Ā 
	
 Ā <head>	
 Ā 
	
 Ā <title>Title</title>	
 Ā 
</head>	
 Ā 
	
 Ā <body>	
 Ā 
…	
 Ā 
</body>	
 Ā 
</html>	
 Ā 
New Structural Tags
Main Goal: separate presentation from content

•  Poor accessibility
•  Unnecessary complexity
•  Larger document size

Most of the presentational features from earlier versions of HTML are no longer supported
New structural tags
New Structural Tags
<header> header region of a page or section
<footer> footer region of a page or section
<nav> navigation region of a page or section
<section> logical region of a page
<article> a complete piece of content
<aside> secondary or related content
http://bit.ly/JCnuQJ
Forms
Main Goal: reduce the Javascript for validation and format management






 


 


 Example:
Form input types
Form Input Types
Form input types degrade gracefully
à 
Unknown input types are treated as text-type
http://bit.ly/I65jai
Audio
<audio> : a standard way to embed an audio file on a web page

<audio controls>
<source src="song.ogg" type="audio/ogg" />
<source src="song.mp3" type="audio/mpeg" />
Not Supported
</audio>
Multiple sources à the browser will use the first recognized format
Audio
Audio Javascript API
HTML5 provides a set of Javascript APIs for interacting with an audio element


For example:

play() pause() load() currentTime ended volume…


à http://www.w3.org/wiki/HTML/Elements/audio
Video
<video> : a standard way to embed a video file on a web page

<video width="320" height="240" controls>
<source src="movie.mp4" type="video/mp4" />
<source src="movie.ogg" type="video/ogg" />
Not Supported
</video>
Multiple sources à the browser will use the first recognized format
Video
Accelerometer

There are 4 ways to store data locally in a web app:
•  Web storage
•  Local Storage
•  Session Storage
•  WebSQL
•  Indexed DB
•  File System Access
Local storage and file system access
Web storage, WebSQL, and IndexedDB 
conform to W3C specifications and are
provided by the browser itself
File system access API conforms to its
corresponding W3C specification
Web Storage

LocalStorage

stores data in key/value pairs

persists across browser sessions

SessionStorage

stores data in key/value pairs

data is erased when a browser session ends
WebSQL


relational DB

support for tables creation, insert, update, …

transactional

persists across browser sessions

You can perform classical SQL queries

tx.executeSql("SELECT	
 Ā *	
 Ā FROM	
 Ā Userā€œ,	
 Ā [],	
 Ā 
	
 Ā function(tx,	
 Ā result)	
 Ā {	
 Ā 
	
 Ā  	
 Ā //	
 Ā callback	
 Ā code	
 Ā 
});	
 Ā 
IndexedDB
•  It tries to combine Web Storage and WebSQL
•  You can save data as key/value pairs
•  You can define multiple DBs
•  Good Performance


data is indexed


asynchronous à it does not block the UI

You can see a store as a big SQL table with only key/value pairs


à you don’t need to define a schema upfront
Considerations
You will likely use more than one API in combination
à Use the right API for the right job

Local Storage
•  it is not transactional à race conditions
•  very simple API, no schema 
•  only String data à performance issues for complex data due to JSON serialization
•  session storage will be cleared after the app is closed
•  limited quota
Considerations

WebSQL
•  SQL-based à fast and efficient
•  transactional à more robust
•  asynchronous à does not block the UI
•  rigid data structure à data integrity vs agility
•  limited quota
Considerations
IndexedDB
•  simple data model à easy to use
•  transactional à more robust
•  asynchronous à does not block the UI
•  good search performance à indexed data
•  data is unstructured à integrity problems
•  limited quota
•  not supported by every platform (e.g., iOS)
Geolocalization

Gets Latitude and Longitude from the user’s browser


There is also a watchPosition method wich calls a JS function every time the user moves


Geolocalization
Example
function getLocation() {
if(navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
console.log(ā€˜no geolocalization’);
}
}
function showPosition(position) {
console.log(position.coords.latitude);
console.log(position.coords.longitude);
}
WebSockets

Bidirectional, full-duplex communication between devices and server

Specifically suited for

chat, videogames, drawings sharing, real-time info

Requires a Web Socket Server to handle the protocol

Web sockets
WebSockets - Overview
1.  Client notifies websocket server (EventMachine) of an event, giving ids of recipients
2.  The server notifies all the active clients (subscribed to that type of event)
3.  Clients process event 

when given recipient Id 

matches the client’s one
http://bit.ly/Ixcupi
Alternative - Polling via AJAX
+ Near real-time updates (not purely real-time)
+ easy to implement
+ no new technologies needed

-  they are requested from the client and cause increased network traffic
-  AJAX requests generally have a small payload and relatively high amount of http headers
(wasted bandwith)
Canvas
Canvas allows you to draw anything inside the browser
http://bit.ly/Ie4HKu
http://bit.ly/LUKXkr
http://bit.ly/LULa79
http://bit.ly/LC8AgY
Canvas
Canvas
It uses nothing more than JavaScript and HTML 

à no external plugins, no libraries, etc.

You can create lines, use images, use text, apply transformations, etc.
http://bit.ly/KsKLv1
Canvas example: the Impavida project
http://www.impavida.com/
Web Workers
Javascript is a single-threaded language
Ć ļƒ ā€ÆIf a tasks take a lot of time, users have to wait
Web Workers provide background processing capabilities to web applications

They typically run on separate threads 

à apps can take advantage of multicore CPUs

Web workers
Web Workers
Web Workers can be used to:
•  prefetch data from the Web
•  perform other ahead-of-time operations to provide a much more lively UI.

Precious on mobile Web applications because of the slow network speed
Web Workers
Any JS file can be launched as a worker

Example of Web Worker declaration:

var worker = new Worker(ā€œworker.jsā€);
In order to be independent from other workers, each worker script cannot access the DOM
Web Workers
The main JS script can communicate with workers via postMessage() calls:


$(ā€˜#button’).click(function(event) {
$(ā€˜#output’).html(ā€œstartingā€);
worker.postMessage(ā€œstartā€);
});
worker.onmessage = function(event) {
$(ā€˜#output’).html(event.data);
}
Web Workers
The web worker script can post back messages to the main script:


onmessage = function(event) {
if(event.data === ā€œstartā€) {
var result;
// do something with result
postMessage(result);
}
}
Roadmap
Anatomy of a web app
Debugging (mobile) web apps
HTML5
The killer app!
•  Check console
•  Breakpoints
•  Update the DOM at run-time
•  Access to all local DBs
•  Network profiling
•  CPU and memory profiling
•  Monitor event listeners
•  Monitor elements’ rendering time
Desktop Browser
Desktop Browser
•  very quick
•  very handy functions
•  see Chrome’s Web Development Tools
•  Breakpoints


PRO
•  browsers’ small differences and bugs
•  cannot test all mobile-specific functionalities
•  you need PhoneGap shims 

CONS
Apache Ripple
Ripple
•  very quick
•  can use Chrome’s Web Development Tools
•  You can test PhoneGap’s API from the Desktop
•  browsers’ small differences and bugs
•  cannot test the interaction with external apps
PRO
CONS
It is based on Ripple, a Chrome
plugin for mobile dev 



from PhoneGap 3.0.0, you need to
use the Ripple available at Apache 
npm	
 Ā install	
 Ā -­‐g	
 Ā ripple-­‐emulator	
 Ā 
ripple	
 Ā emulate	
 Ā 
Simulator
•  Officially supported by platform vendors 

•  You use the ā€œrealā€ device’s browser
PRO
•  device’s performance is not considered 
•  this is iOS-specific
•  Android’s emulator is a joke
•  device’s capabilities are only simulated
CONS
On device
•  accurate
•  still handy
•  real performance tests
•  real browser tests
PRO
•  Deployment takes some time (~6 seconds for iOS)
CONS
Remote Debugging
From iOS 6, Apple provided Mobile Safari with a remote web inspector
à You can debug your app by using the classical web inspector of Desktop Safari

It can connect both to
•  The iOS emulator
•  The real device

Since Android 4.4, this feature is
available via Chrome’s web dev kit
Mobile debugging reference table 
Make a favor to yourself, 
don’t debug craftsman way:

console.log()	
 Ā +	
 Ā alert()	
 Ā 

iOS
 Android
Desktop Browser
 
 
Ripple
 
 
Device/emulator
 
 
Safari Web
Inspector

 X
Chrome Web
Inspector
X
Roadmap
Anatomy of a web app
Debugging (mobile) web apps
HTML5
Maintainable web apps
Roadmap
•  Introduction
•  Backbone 
•  Require JS
•  Handlebars
•  Combining backbone, Require, and Handlebars
Introduction
We are building apps, not web sites

If your code is not structured:
•  it is extremely easy that your web app becomes a 

 
big mess of HTML + CSS + JavaScript
•  maintaining each part of your app asks for a 

 
deep analysis of ALL its aspects (logic, presentation, etc.)
•  you may waste a whole day due to a missing 	
 Ā <	
 Ā 
What we want to avoid





Imagine yourself trying to change either: 
•  how a movie should be rendered in your app
•  the REST API providing info about movies
Roadmap
•  Introduction
•  Backbone 
•  Require JS
•  Handlebars
•  Combining backbone, Require, and Handlebars
Why Backbone

Backbone gives you
 STRUCTURE
Why Backbone

From the Backbone website...
manipulate 
the DOM
lists 
of models
represent 
data
Who is using Backbone?
Backbone events


Basically, each object can:
•  listen to events
•  trigger events
Models

Models represent your data

Each model represents a data type in your app, together with the logic surrounding it, like:
•  persistence
•  conversions
•  validation
•  computed properties
•  access control
MVC: Notify their observers about their
state using the Observer pattern
Example of model
http://goo.gl/UOahsP
custom method
setting an 
attribute
custom method
invocation
constructor
default attributes
getting an 
attribute
Models API overview
Collections
Collections are ordered sets of models

You can: 
•  bindĀ changeĀ events to be notified when any model in the collection has been modified
•  listen forĀ addĀ andĀ remove events
•  fetchĀ the collection from the server (or other persistence layers)
•  find models or filter collections themeselves

The model attribute of a collection represents the kind of model that can be stored in it
Any event that is triggered on a model in a collection
will also be triggered on the collection directly
MVC: Notify their observers
about state using the Observer
pattern (same as models)
Example of collection
http://goo.gl/UOahsP
type of stored
models
Instance of
collection
Collections API overview
Views
Views represent and manage the visible parts of your application

They are also used to 
•  listen to interaction events 
•  and react accordingly

views can be rendered at any time, and inserted into the DOM

 you get high-performance UI rendering 
with as few reflows and repaints as possible
MVC: observe models, and
update itself according to the
state of the models + manage
user inputs (it’s a controller, to
this sense)
Example of view
Events map
ā€œevent_name selectorā€: callback
Events callbacks
create the
DOM subtree
Views API overview
The router
Backbone.Router	
 Ā provides methods for routing client-side pages, 
and connecting them to actions and events

At a minimum, a router is composed of two main parts:
routes


an hash that pairs routes to actions 
actions


JS functions triggered when certain routes are navigated
Example of router
routes map
routing
functions
Backbone-based workflow
•  You organize your interface into logical views backed by models
•  Each view can be updated independently when the model changes,
without having to redraw the page
You can bind your viewā€˜s
render() function to the
modelā€˜s "changeā€ event 

à 
now everywhere that
model data is displayed in the
UI, it is always up to date
Roadmap
•  Introduction
•  Backbone 
•  Require JS
•  Handlebars
•  Combining backbone, Require, and Handlebars
Why Require JS

We are building apps, not website

We need well-specified and isolated JS files/modules

Code complexity grows as the app gets bigger




 
à we need some sort of #include/import/require	
 Ā 


à ability to load nested dependencies
What we want to avoid












 




 
 
 
 
 
uncontrolled scripts
poor control flow understanding
Require JS
RequireJS is a JavaScript file and module loader
Using a modular script loader like Require JS will improve the modularity of your code:
Ć ļƒ ā€Æ speed in implementing changes
Ć ļƒ ā€Æ better undestanding of the code

Require JS allows modules to be loaded as fast as possible, even out of order, but evaluated in the
correct dependency order
It is built on the Module Pattern
JavaScript file and module loader
Module example

Technically, it is simply a function that executes immediately
Module VS script files






A module is different from a traditional script file in that it defines a well-scoped object that avoids
polluting the global namespace à its retained objects can be deleted by the GC
It can explicitly list its dependencies and get a handle on those dependencies without needing to refer to
global objects, but instead receive the dependencies as arguments to the function that defines the
module
VS
Module definition
Required
modules (array)
References to required modules
Dependent module usage
This function is called when
zepto.js is loaded. 
If zepto.js calls define(), then
this function is not fired until
also zepto’s dependencies
have loaded
Require JS under the hoods...
1.  loads each dependency as a script tag, using head.appendChild() and waits for all dependencies to
load
2.  computes the right order in which to call the functions that define the modules
3.  calls the module definition functions of each dependency in the right order
main.js
jQuery
 Backbone
SpinJS
MoviesCollection
MovieModel
MoviesView
1
2
3
 4
5
6
7
Roadmap
•  Introduction
•  Backbone 
•  Require JS
•  Handlebars
•  Combining backbone, Require, and Handlebars
Why Handlebars
We want to separate presentation from logic
TRANSLATE TO: we don’t want to put any HTML element into JavaScript code
separate logic from presentation
Imagine yourself trying to change how a movie should be rendered in
your app...
Handlebars template
A handlebars expression is 

{{ somethingĀ  }}
Template compilation
	
 Ā 
Handlebars.compile is used to compile a template




Compiling = obtaining a JS object representing the template
Templates population
You have to execute a template with a context
in order to get its corresponding HTML code
Handlebars summary
Each Template can contain Expressions and Helpers operating on them

The main helpers are: 
•  with	
 Ā 
•  each	
 Ā 
•  if	
 Ā /	
 Ā else	
 Ā /unless	
 Ā 


You can define your own Helpers that operate on expressions, they return HTML code


A template can be (pre)-compiled and must be executed with a context in order to return the
final HTML fragment
Example of built-in helper


It renders the block if its argument is not equal to false,	
 Ā undefined,	
 Ā null,	
 Ā []	
 Ā 
If / Else
<div	
 Ā class="entryā€œ>	
 Ā 
<h1>{{title}}</h1>	
 Ā 
{{#if	
 Ā author}}	
 Ā 
	
 Ā <h2>By	
 Ā {{firstName}}	
 Ā {{lastName}}</h2>	
 Ā 
{{#else}}	
 Ā 
	
 Ā <h2>Unknown	
 Ā author</h1>	
 Ā 	
 Ā 
{{/if}}	
 Ā 
</div>	
 Ā 	
 Ā 
{	
 Ā title:	
 Ā "My	
 Ā first	
 Ā post!",	
 Ā 	
 Ā 
	
 Ā 	
 Ā 	
 Ā author:	
 Ā undefined	
 Ā }	
 Ā 
}	
 Ā 	
 Ā 
<div	
 Ā class="entryā€œ>	
 Ā 
<h1>My	
 Ā first	
 Ā post!</h1>	
 Ā 
<h2>Unknown	
 Ā author</h2>	
 Ā 
</div>	
 Ā 	
 Ā 
Roadmap
•  Introduction
•  Backbone 
•  Require JS
•  Handlebars
•  Combining backbone, Require, and Handlebars
Combining Backbone, Require, and Handlebars
Handlebars templates can be seen as special Require modules

So we can have the following:

•  a separate HTML5 file for each template 
•  a Backbone view can have a dependency to each template
•  the template can be executed by using a JSON object of the Backbone model as context
Example
Dependency to template HTML file
It contains a string 
Compiled template
Execution of the template
How I structure my mobile web apps
I implemented all best practices and advices in this
presentation in a generic app template available here:

https://github.com/iivanoo/cordovaboilerplate
Towards automation…
Towards a Collaborative Framework for the Design and Development of Data-
Intensive Mobile Applications. Mirco Franzago, Ivano Malavolta, Henry Muccini.
Proceedings of the 1st ACM International Conference on Mobile Software
Engineering and Systems, June 2-3, 2014 Hyderabad, India
References
http://backbonejs.org
http://requirejs.org
http://handlebarsjs.com
https://github.com/iivanoo/cordovaboilerplate
+ 39 380 70 21 600
Contact
Ivano Malavolta |
Gran Sasso Science Institute
iivanoo
ivano.malavolta@univaq.it
www.ivanomalavolta.com

More Related Content

What's hot (20)

PDF
Workshop HTML5+PhoneGap by Ivano Malavolta
Commit University
Ā 
PPTX
2/15/2012 - Wrapping Your Head Around the SharePoint Beast
Mark Rackley
Ā 
PDF
Sightly - AEM6 UI Development using JS and JAVA
Yash Mody
Ā 
PDF
Apache Cordova 4.x
Ivano Malavolta
Ā 
PDF
WebNet Conference 2012 - Designing complex applications using html5 and knock...
Fabio Franzini
Ā 
PPTX
SPTechCon - Share point and jquery essentials
Mark Rackley
Ā 
PDF
[2015/2016] HTML5 and CSS3 Refresher
Ivano Malavolta
Ā 
PDF
HTML5 & CSS3 refresher for mobile apps
Ivano Malavolta
Ā 
PDF
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
SPTechCon
Ā 
PPTX
SharePoint Saturday St. Louis - SharePoint & jQuery
Mark Rackley
Ā 
PPTX
Bringing HTML5 alive in SharePoint
Chad Schroeder
Ā 
PPTX
Codemotion 2013 - Designing complex applications using html5 and knockoutjs
Fabio Franzini
Ā 
PPTX
SPSDenver - SharePoint & jQuery - What I wish I would have known
Mark Rackley
Ā 
PDF
Building search app with ElasticSearch
Lukas Vlcek
Ā 
PPTX
MVC & SQL_In_1_Hour
Dilip Patel
Ā 
PPTX
AEM - Client Libraries
Prabhdeep Singh
Ā 
PDF
Angular mobile angular_u
Doris Chen
Ā 
PPTX
RapidApp - YAPC::NA 2014
Henry Van Styn
Ā 
PPT
Ruby on Rails: Building Web Applications Is Fun Again!
judofyr
Ā 
PDF
tTecniche di sviluppo mobile per share point 2013 e office 365
Fabio Franzini
Ā 
Workshop HTML5+PhoneGap by Ivano Malavolta
Commit University
Ā 
2/15/2012 - Wrapping Your Head Around the SharePoint Beast
Mark Rackley
Ā 
Sightly - AEM6 UI Development using JS and JAVA
Yash Mody
Ā 
Apache Cordova 4.x
Ivano Malavolta
Ā 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
Fabio Franzini
Ā 
SPTechCon - Share point and jquery essentials
Mark Rackley
Ā 
[2015/2016] HTML5 and CSS3 Refresher
Ivano Malavolta
Ā 
HTML5 & CSS3 refresher for mobile apps
Ivano Malavolta
Ā 
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
SPTechCon
Ā 
SharePoint Saturday St. Louis - SharePoint & jQuery
Mark Rackley
Ā 
Bringing HTML5 alive in SharePoint
Chad Schroeder
Ā 
Codemotion 2013 - Designing complex applications using html5 and knockoutjs
Fabio Franzini
Ā 
SPSDenver - SharePoint & jQuery - What I wish I would have known
Mark Rackley
Ā 
Building search app with ElasticSearch
Lukas Vlcek
Ā 
MVC & SQL_In_1_Hour
Dilip Patel
Ā 
AEM - Client Libraries
Prabhdeep Singh
Ā 
Angular mobile angular_u
Doris Chen
Ā 
RapidApp - YAPC::NA 2014
Henry Van Styn
Ā 
Ruby on Rails: Building Web Applications Is Fun Again!
judofyr
Ā 
tTecniche di sviluppo mobile per share point 2013 e office 365
Fabio Franzini
Ā 

Similar to HTML5: the new frontier of the web (20)

PDF
Anatomy of an HTML 5 mobile web app
Ivano Malavolta
Ā 
PDF
Trends in front end engineering_handouts
AE - architects for business and ict
Ā 
PDF
Hybrid mobile apps
Erik Paulsson
Ā 
PDF
HTML5 or Android for Mobile Development?
Reto Meier
Ā 
PDF
HTML5 and the dawn of rich mobile web applications
James Pearce
Ā 
PPTX
Mobile applications for SharePoint using HTML5
Christian Heindel
Ā 
PDF
Hybridmobileapps 130130213844-phpapp02
weeyee
Ā 
PDF
HTML5 Can't Do That
Nathan Smith
Ā 
PDF
Desarrollo de apps multiplataforma con tecnologĆ­as web
Software Guru
Ā 
PDF
Sg conference multiplatform_apps_adam_stanley
n_adam_stanley
Ā 
PDF
HTML5 Technical Executive Summary
Gilad Khen
Ā 
PDF
Building Cross Platform Mobile Web Apps
James Pearce
Ā 
PDF
HTML5 and the dawn of rich mobile web applications pt 1
James Pearce
Ā 
PPTX
Mobile Apps Develpment - A Comparison
Lataant Software Technologies
Ā 
KEY
Mobile ECM with JavaScript - JSE 2011
Nuxeo
Ā 
PPTX
Html5
Zahin Omar Alwa
Ā 
PPTX
HTML5: The Apps, the Frameworks, the Controversy
Apigee | Google Cloud
Ā 
PPTX
HTML5 on Mobile
Adam Lu
Ā 
PDF
An Intro to Mobile HTML5
James Pearce
Ā 
KEY
HTML5 is the Future of Mobile, PhoneGap Takes You There Today
davyjones
Ā 
Anatomy of an HTML 5 mobile web app
Ivano Malavolta
Ā 
Trends in front end engineering_handouts
AE - architects for business and ict
Ā 
Hybrid mobile apps
Erik Paulsson
Ā 
HTML5 or Android for Mobile Development?
Reto Meier
Ā 
HTML5 and the dawn of rich mobile web applications
James Pearce
Ā 
Mobile applications for SharePoint using HTML5
Christian Heindel
Ā 
Hybridmobileapps 130130213844-phpapp02
weeyee
Ā 
HTML5 Can't Do That
Nathan Smith
Ā 
Desarrollo de apps multiplataforma con tecnologĆ­as web
Software Guru
Ā 
Sg conference multiplatform_apps_adam_stanley
n_adam_stanley
Ā 
HTML5 Technical Executive Summary
Gilad Khen
Ā 
Building Cross Platform Mobile Web Apps
James Pearce
Ā 
HTML5 and the dawn of rich mobile web applications pt 1
James Pearce
Ā 
Mobile Apps Develpment - A Comparison
Lataant Software Technologies
Ā 
Mobile ECM with JavaScript - JSE 2011
Nuxeo
Ā 
HTML5: The Apps, the Frameworks, the Controversy
Apigee | Google Cloud
Ā 
HTML5 on Mobile
Adam Lu
Ā 
An Intro to Mobile HTML5
James Pearce
Ā 
HTML5 is the Future of Mobile, PhoneGap Takes You There Today
davyjones
Ā 
Ad

More from Ivano Malavolta (20)

PDF
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
Ivano Malavolta
Ā 
PDF
Conducting Experiments on the Software Architecture of Robotic Systems (QRARS...
Ivano Malavolta
Ā 
PDF
The H2020 experience
Ivano Malavolta
Ā 
PDF
The Green Lab - Research cocktail @Vrije Universiteit Amsterdam (October 2020)
Ivano Malavolta
Ā 
PDF
Software sustainability and Green IT
Ivano Malavolta
Ā 
PDF
Navigation-aware and Personalized Prefetching of Network Requests in Android ...
Ivano Malavolta
Ā 
PDF
How Maintainability Issues of Android Apps Evolve [ICSME 2018]
Ivano Malavolta
Ā 
PDF
Collaborative Model-Driven Software Engineering: a Classification Framework a...
Ivano Malavolta
Ā 
PDF
Experimenting on Mobile Apps Quality - a tale about Energy, Performance, and ...
Ivano Malavolta
Ā 
PDF
Modeling objects interaction via UML sequence diagrams [Software Design] [Com...
Ivano Malavolta
Ā 
PDF
Modeling behaviour via UML state machines [Software Design] [Computer Science...
Ivano Malavolta
Ā 
PDF
Object-oriented design patterns in UML [Software Design] [Computer Science] [...
Ivano Malavolta
Ā 
PDF
Structure modeling with UML [Software Design] [Computer Science] [Vrije Unive...
Ivano Malavolta
Ā 
PDF
Requirements engineering with UML [Software Design] [Computer Science] [Vrije...
Ivano Malavolta
Ā 
PDF
Modeling and abstraction, software development process [Software Design] [Com...
Ivano Malavolta
Ā 
PDF
[2017/2018] Agile development
Ivano Malavolta
Ā 
PDF
Reconstructing microservice-based architectures
Ivano Malavolta
Ā 
PDF
[2017/2018] AADL - Architecture Analysis and Design Language
Ivano Malavolta
Ā 
PDF
[2017/2018] Architectural languages
Ivano Malavolta
Ā 
PDF
[2017/2018] Introduction to Software Architecture
Ivano Malavolta
Ā 
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
Ivano Malavolta
Ā 
Conducting Experiments on the Software Architecture of Robotic Systems (QRARS...
Ivano Malavolta
Ā 
The H2020 experience
Ivano Malavolta
Ā 
The Green Lab - Research cocktail @Vrije Universiteit Amsterdam (October 2020)
Ivano Malavolta
Ā 
Software sustainability and Green IT
Ivano Malavolta
Ā 
Navigation-aware and Personalized Prefetching of Network Requests in Android ...
Ivano Malavolta
Ā 
How Maintainability Issues of Android Apps Evolve [ICSME 2018]
Ivano Malavolta
Ā 
Collaborative Model-Driven Software Engineering: a Classification Framework a...
Ivano Malavolta
Ā 
Experimenting on Mobile Apps Quality - a tale about Energy, Performance, and ...
Ivano Malavolta
Ā 
Modeling objects interaction via UML sequence diagrams [Software Design] [Com...
Ivano Malavolta
Ā 
Modeling behaviour via UML state machines [Software Design] [Computer Science...
Ivano Malavolta
Ā 
Object-oriented design patterns in UML [Software Design] [Computer Science] [...
Ivano Malavolta
Ā 
Structure modeling with UML [Software Design] [Computer Science] [Vrije Unive...
Ivano Malavolta
Ā 
Requirements engineering with UML [Software Design] [Computer Science] [Vrije...
Ivano Malavolta
Ā 
Modeling and abstraction, software development process [Software Design] [Com...
Ivano Malavolta
Ā 
[2017/2018] Agile development
Ivano Malavolta
Ā 
Reconstructing microservice-based architectures
Ivano Malavolta
Ā 
[2017/2018] AADL - Architecture Analysis and Design Language
Ivano Malavolta
Ā 
[2017/2018] Architectural languages
Ivano Malavolta
Ā 
[2017/2018] Introduction to Software Architecture
Ivano Malavolta
Ā 
Ad

Recently uploaded (20)

PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
Ā 
PPT
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
Ā 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
Ā 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
Ā 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
Ā 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
Ā 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
Ā 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
Ā 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
Ā 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
Ā 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
Ā 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
Ā 
PPTX
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
Ā 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
Ā 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
Ā 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
Ā 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
Ā 
PDF
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
Ā 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
Ā 
PPTX
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
Ā 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
Ā 
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
Ā 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
Ā 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
Ā 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
Ā 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
Ā 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
Ā 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
Ā 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
Ā 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
Ā 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
Ā 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
Ā 
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
Ā 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
Ā 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
Ā 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
Ā 
Smart Trailers 2025 Update with History and Overview
Paul Menig
Ā 
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
Ā 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
Ā 
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
Ā 

HTML5: the new frontier of the web

  • 1. Gran Sasso Science Institute | University of L’Aquila Ivano Malavolta HTML5: the new frontier of the web
  • 2. About me… Ivano Malavolta Post Doc researcher – Gran Sasso Science Institute www.ivanomalavolta.com
  • 3. Roadmap Anatomy of a web app Debugging (mobile) web apps HTML5 Maintainable web apps
  • 5. What is a Web App? A software built with web technologies that is accessible via a mobile browser The browser may be either the standard device browser or an embedded browser (Hybrid app)
  • 6. Anatomy of a Web App
  • 7. Setting up the Server As usual, it all starts with an HTTP request Then you need: •  Data •  A device detection mechanism [optional] •  The app itself
  • 8. Data Usually mobile apps do not talk directly with the database à do not even think about JDBC, drivers, etc! Ć ļƒ ā€Æ They pass through an application server and communicate via: •  standard HTTP requests for HTML content (eg PHP) •  REST-full services (XML, JSON, etc.) •  SOAP
  • 9. Data •  Data can be stored in any classical way: •  Relational •  Graph •  Key-value •  Document-based Latest trend à backend-as-a-service
  • 10. BaaS 1.  Developers build a visual model of their DB 2.  The service generates APIs and client-side libraries(compatible with Android, Windows Phone, etc.) 3.  The data produced/consumed in the app can be pushed/pulled to their DB •  Communication is handled via REST-based APIs
  • 11. Example of Baas software: BaasBox Main features: •  User management •  ACL •  Friendships •  Authentication via Facebook and Google+ •  Document-based data manegement (via OrientDB) •  Assets management (fotos, documents, or files) •  Push notifications The ā€œBoxā€ in BaasBox means that all the features are in a standalone server, just like a box. No Application Server, no Database Server, just a JVM and nothing more Rest API Web dashboard http://www.baasbox.com/
  • 12. Ok, but what about mobile apps? BROWSER <html> <head> <script src=ā€ ...ā€ /> </head> <body> ... NATIVE WRAPPER <html> <head> <script src=ā€ ...ā€ /> </head> <body> ... PLATFORM APIs NATIVE APP 01010101010101101010 1010101011011010 010101010101011101 010101010101011010 PLATFORM APIs Native Web Hybrid
  • 13. Native http://bit.ly/GWOaP1 PRO •  Lets you create apps with rich user interfaces and/or heavy graphics CONS •  Development Time •  Development Cost •  Ongoing Maintenance •  No portability (apps cannot be used on other platforms) PRO CONS
  • 14. Examples of native apps http://www.ea.com/it/ipad/nfs http://www.whatsapp.com/
  • 15. Web http://bit.ly/GWOaP1 PRO •  Offers fast development, simple maintenance, and full application portability •  One mobile web app works on any platform CONS •  Can’t handle heavy graphics •  Can’t access camera or push notifications PRO CONS
  • 16. Examples of web apps http://asidemag.com http://amazon.com
  • 17. Hybrid http://bit.ly/GWOaP1 PRO •  Development speed of mobile web apps •  Device access and app store distribution of native apps CONS •  Can’t handle heavy graphics •  Requires familiarity with a mobile framework PRO CONS
  • 18. Examples of hybrid apps http://www.gmail.com http://flipboard.com
  • 19. Frascati Scienza QR code scanning In-app RSS feed reader Maps Non-linear layouts https://itunes.apple.com/it/app/frascati-scienza-scienziati/id686974321?mt=8
  • 21. My vision Mobile web seems to be the only long-term commercially viable platform for mobile FRAGMENTATION THE WEB USER EXPECTATIONS
  • 22. When you go native there are too many platforms to be supported FRAGMENTATION
  • 23. The web is the only platform that: •  works across devices •  apps share the same set of standards •  the same app can work also on a desktop THE WEB The web is an advanced technology: •  webGL •  Local storage management •  Positioning & mapping •  Real-time data •  ...
  • 24. Users expect things to just work à they don’t care about what platform they have àthey simply expect that your app will be available for their device à YOU HAVE TO BE CROSS-PLATFORM USER EXPECTATIONS
  • 25. PhoneGap You develop your app using the usual three guys You use the same web view of the native OS •  iOS = UIWebView •  Android = android.webkit.WebView http://phonegap.com/blog/2013/06/20/coming-soon-phonegap30
  • 26. What is PhoneGap? The UI layer is a web browser view •  100% width •  100% height Headless web browser •  No URL bar •  No decorations •  No zooming •  No text selection
  • 27. It looks very similar to Apache Cordova… Adobe/Nitobi donated the PhoneGap codebase to the Apache foundation à wider audience and contributors à transparent governance Better documentation à easier contributions for companies Apache Licensing There was only one problem.... trademark ambiguity à CORDOVA PhoneGap is a distribution of Apache Cordova
  • 28. Roadmap Anatomy of a web app HTML5
  • 29. HTML 5 HTML5 will be the new standard for HTML HTML5 is still a work in progress W3C final recomendation: 2020 Top browsers support many (not all) of the new HTML5 elements http://mobilehtml5.org http://caniuse.com
  • 30. What is HTML5? HTML5 Markup JavaScript CSS3 Multimedia
  • 31. The minimal HTML5 page <!DOCTYPE Ā html> Ā  <html> Ā  Ā <head> Ā  Ā <title>Title</title> Ā  </head> Ā  Ā <body> Ā  … Ā  </body> Ā  </html> Ā 
  • 32. New Structural Tags Main Goal: separate presentation from content •  Poor accessibility •  Unnecessary complexity •  Larger document size Most of the presentational features from earlier versions of HTML are no longer supported New structural tags
  • 33. New Structural Tags <header> header region of a page or section <footer> footer region of a page or section <nav> navigation region of a page or section <section> logical region of a page <article> a complete piece of content <aside> secondary or related content http://bit.ly/JCnuQJ
  • 34. Forms Main Goal: reduce the Javascript for validation and format management Example: Form input types
  • 35. Form Input Types Form input types degrade gracefully à Unknown input types are treated as text-type http://bit.ly/I65jai
  • 36. Audio <audio> : a standard way to embed an audio file on a web page <audio controls> <source src="song.ogg" type="audio/ogg" /> <source src="song.mp3" type="audio/mpeg" /> Not Supported </audio> Multiple sources à the browser will use the first recognized format Audio
  • 37. Audio Javascript API HTML5 provides a set of Javascript APIs for interacting with an audio element For example: play() pause() load() currentTime ended volume… à http://www.w3.org/wiki/HTML/Elements/audio
  • 38. Video <video> : a standard way to embed a video file on a web page <video width="320" height="240" controls> <source src="movie.mp4" type="video/mp4" /> <source src="movie.ogg" type="video/ogg" /> Not Supported </video> Multiple sources à the browser will use the first recognized format Video
  • 39. Accelerometer There are 4 ways to store data locally in a web app: •  Web storage •  Local Storage •  Session Storage •  WebSQL •  Indexed DB •  File System Access Local storage and file system access Web storage, WebSQL, and IndexedDB conform to W3C specifications and are provided by the browser itself File system access API conforms to its corresponding W3C specification
  • 40. Web Storage LocalStorage stores data in key/value pairs persists across browser sessions SessionStorage stores data in key/value pairs data is erased when a browser session ends
  • 41. WebSQL relational DB support for tables creation, insert, update, … transactional persists across browser sessions You can perform classical SQL queries tx.executeSql("SELECT Ā * Ā FROM Ā Userā€œ, Ā [], Ā  Ā function(tx, Ā result) Ā { Ā  Ā  Ā // Ā callback Ā code Ā  }); Ā 
  • 42. IndexedDB •  It tries to combine Web Storage and WebSQL •  You can save data as key/value pairs •  You can define multiple DBs •  Good Performance data is indexed asynchronous à it does not block the UI You can see a store as a big SQL table with only key/value pairs à you don’t need to define a schema upfront
  • 43. Considerations You will likely use more than one API in combination à Use the right API for the right job Local Storage •  it is not transactional à race conditions •  very simple API, no schema •  only String data à performance issues for complex data due to JSON serialization •  session storage will be cleared after the app is closed •  limited quota
  • 44. Considerations WebSQL •  SQL-based à fast and efficient •  transactional à more robust •  asynchronous à does not block the UI •  rigid data structure à data integrity vs agility •  limited quota
  • 45. Considerations IndexedDB •  simple data model à easy to use •  transactional à more robust •  asynchronous à does not block the UI •  good search performance à indexed data •  data is unstructured à integrity problems •  limited quota •  not supported by every platform (e.g., iOS)
  • 46. Geolocalization Gets Latitude and Longitude from the user’s browser There is also a watchPosition method wich calls a JS function every time the user moves Geolocalization
  • 47. Example function getLocation() { if(navigator.geolocation) { navigator.geolocation.getCurrentPosition(showPosition); } else { console.log(ā€˜no geolocalization’); } } function showPosition(position) { console.log(position.coords.latitude); console.log(position.coords.longitude); }
  • 48. WebSockets Bidirectional, full-duplex communication between devices and server Specifically suited for chat, videogames, drawings sharing, real-time info Requires a Web Socket Server to handle the protocol Web sockets
  • 49. WebSockets - Overview 1.  Client notifies websocket server (EventMachine) of an event, giving ids of recipients 2.  The server notifies all the active clients (subscribed to that type of event) 3.  Clients process event when given recipient Id matches the client’s one http://bit.ly/Ixcupi
  • 50. Alternative - Polling via AJAX + Near real-time updates (not purely real-time) + easy to implement + no new technologies needed -  they are requested from the client and cause increased network traffic -  AJAX requests generally have a small payload and relatively high amount of http headers (wasted bandwith)
  • 51. Canvas Canvas allows you to draw anything inside the browser http://bit.ly/Ie4HKu http://bit.ly/LUKXkr http://bit.ly/LULa79 http://bit.ly/LC8AgY Canvas
  • 52. Canvas It uses nothing more than JavaScript and HTML à no external plugins, no libraries, etc. You can create lines, use images, use text, apply transformations, etc. http://bit.ly/KsKLv1
  • 53. Canvas example: the Impavida project http://www.impavida.com/
  • 54. Web Workers Javascript is a single-threaded language Ć ļƒ ā€ÆIf a tasks take a lot of time, users have to wait Web Workers provide background processing capabilities to web applications They typically run on separate threads à apps can take advantage of multicore CPUs Web workers
  • 55. Web Workers Web Workers can be used to: •  prefetch data from the Web •  perform other ahead-of-time operations to provide a much more lively UI. Precious on mobile Web applications because of the slow network speed
  • 56. Web Workers Any JS file can be launched as a worker Example of Web Worker declaration: var worker = new Worker(ā€œworker.jsā€); In order to be independent from other workers, each worker script cannot access the DOM
  • 57. Web Workers The main JS script can communicate with workers via postMessage() calls: $(ā€˜#button’).click(function(event) { $(ā€˜#output’).html(ā€œstartingā€); worker.postMessage(ā€œstartā€); }); worker.onmessage = function(event) { $(ā€˜#output’).html(event.data); }
  • 58. Web Workers The web worker script can post back messages to the main script: onmessage = function(event) { if(event.data === ā€œstartā€) { var result; // do something with result postMessage(result); } }
  • 59. Roadmap Anatomy of a web app Debugging (mobile) web apps HTML5
  • 60. The killer app! •  Check console •  Breakpoints •  Update the DOM at run-time •  Access to all local DBs •  Network profiling •  CPU and memory profiling •  Monitor event listeners •  Monitor elements’ rendering time
  • 62. Desktop Browser •  very quick •  very handy functions •  see Chrome’s Web Development Tools •  Breakpoints PRO •  browsers’ small differences and bugs •  cannot test all mobile-specific functionalities •  you need PhoneGap shims CONS
  • 64. Ripple •  very quick •  can use Chrome’s Web Development Tools •  You can test PhoneGap’s API from the Desktop •  browsers’ small differences and bugs •  cannot test the interaction with external apps PRO CONS It is based on Ripple, a Chrome plugin for mobile dev from PhoneGap 3.0.0, you need to use the Ripple available at Apache npm Ā install Ā -­‐g Ā ripple-­‐emulator Ā  ripple Ā emulate Ā 
  • 65. Simulator •  Officially supported by platform vendors •  You use the ā€œrealā€ device’s browser PRO •  device’s performance is not considered •  this is iOS-specific •  Android’s emulator is a joke •  device’s capabilities are only simulated CONS
  • 66. On device •  accurate •  still handy •  real performance tests •  real browser tests PRO •  Deployment takes some time (~6 seconds for iOS) CONS
  • 67. Remote Debugging From iOS 6, Apple provided Mobile Safari with a remote web inspector à You can debug your app by using the classical web inspector of Desktop Safari It can connect both to •  The iOS emulator •  The real device Since Android 4.4, this feature is available via Chrome’s web dev kit
  • 68. Mobile debugging reference table Make a favor to yourself, don’t debug craftsman way: console.log() Ā + Ā alert() Ā  iOS Android Desktop Browser Ripple Device/emulator Safari Web Inspector X Chrome Web Inspector X
  • 69. Roadmap Anatomy of a web app Debugging (mobile) web apps HTML5 Maintainable web apps
  • 70. Roadmap •  Introduction •  Backbone •  Require JS •  Handlebars •  Combining backbone, Require, and Handlebars
  • 71. Introduction We are building apps, not web sites If your code is not structured: •  it is extremely easy that your web app becomes a big mess of HTML + CSS + JavaScript •  maintaining each part of your app asks for a deep analysis of ALL its aspects (logic, presentation, etc.) •  you may waste a whole day due to a missing Ā < Ā 
  • 72. What we want to avoid Imagine yourself trying to change either: •  how a movie should be rendered in your app •  the REST API providing info about movies
  • 73. Roadmap •  Introduction •  Backbone •  Require JS •  Handlebars •  Combining backbone, Require, and Handlebars
  • 75. Why Backbone From the Backbone website... manipulate the DOM lists of models represent data
  • 76. Who is using Backbone?
  • 77. Backbone events Basically, each object can: •  listen to events •  trigger events
  • 78. Models Models represent your data Each model represents a data type in your app, together with the logic surrounding it, like: •  persistence •  conversions •  validation •  computed properties •  access control MVC: Notify their observers about their state using the Observer pattern
  • 79. Example of model http://goo.gl/UOahsP custom method setting an attribute custom method invocation constructor default attributes getting an attribute
  • 81. Collections Collections are ordered sets of models You can: •  bindĀ changeĀ events to be notified when any model in the collection has been modified •  listen forĀ addĀ andĀ remove events •  fetchĀ the collection from the server (or other persistence layers) •  find models or filter collections themeselves The model attribute of a collection represents the kind of model that can be stored in it Any event that is triggered on a model in a collection will also be triggered on the collection directly MVC: Notify their observers about state using the Observer pattern (same as models)
  • 84. Views Views represent and manage the visible parts of your application They are also used to •  listen to interaction events •  and react accordingly views can be rendered at any time, and inserted into the DOM you get high-performance UI rendering with as few reflows and repaints as possible MVC: observe models, and update itself according to the state of the models + manage user inputs (it’s a controller, to this sense)
  • 85. Example of view Events map ā€œevent_name selectorā€: callback Events callbacks create the DOM subtree
  • 87. The router Backbone.Router Ā provides methods for routing client-side pages, and connecting them to actions and events At a minimum, a router is composed of two main parts: routes an hash that pairs routes to actions actions JS functions triggered when certain routes are navigated
  • 88. Example of router routes map routing functions
  • 89. Backbone-based workflow •  You organize your interface into logical views backed by models •  Each view can be updated independently when the model changes, without having to redraw the page You can bind your viewā€˜s render() function to the modelā€˜s "changeā€ event à now everywhere that model data is displayed in the UI, it is always up to date
  • 90. Roadmap •  Introduction •  Backbone •  Require JS •  Handlebars •  Combining backbone, Require, and Handlebars
  • 91. Why Require JS We are building apps, not website We need well-specified and isolated JS files/modules Code complexity grows as the app gets bigger à we need some sort of #include/import/require Ā  à ability to load nested dependencies
  • 92. What we want to avoid uncontrolled scripts poor control flow understanding
  • 93. Require JS RequireJS is a JavaScript file and module loader Using a modular script loader like Require JS will improve the modularity of your code: Ć ļƒ ā€Æ speed in implementing changes Ć ļƒ ā€Æ better undestanding of the code Require JS allows modules to be loaded as fast as possible, even out of order, but evaluated in the correct dependency order It is built on the Module Pattern JavaScript file and module loader
  • 94. Module example Technically, it is simply a function that executes immediately
  • 95. Module VS script files A module is different from a traditional script file in that it defines a well-scoped object that avoids polluting the global namespace à its retained objects can be deleted by the GC It can explicitly list its dependencies and get a handle on those dependencies without needing to refer to global objects, but instead receive the dependencies as arguments to the function that defines the module VS
  • 96. Module definition Required modules (array) References to required modules Dependent module usage This function is called when zepto.js is loaded. If zepto.js calls define(), then this function is not fired until also zepto’s dependencies have loaded
  • 97. Require JS under the hoods... 1.  loads each dependency as a script tag, using head.appendChild() and waits for all dependencies to load 2.  computes the right order in which to call the functions that define the modules 3.  calls the module definition functions of each dependency in the right order main.js jQuery Backbone SpinJS MoviesCollection MovieModel MoviesView 1 2 3 4 5 6 7
  • 98. Roadmap •  Introduction •  Backbone •  Require JS •  Handlebars •  Combining backbone, Require, and Handlebars
  • 99. Why Handlebars We want to separate presentation from logic TRANSLATE TO: we don’t want to put any HTML element into JavaScript code separate logic from presentation Imagine yourself trying to change how a movie should be rendered in your app...
  • 100. Handlebars template A handlebars expression is {{ somethingĀ  }}
  • 101. Template compilation Ā  Handlebars.compile is used to compile a template Compiling = obtaining a JS object representing the template
  • 102. Templates population You have to execute a template with a context in order to get its corresponding HTML code
  • 103. Handlebars summary Each Template can contain Expressions and Helpers operating on them The main helpers are: •  with Ā  •  each Ā  •  if Ā / Ā else Ā /unless Ā  You can define your own Helpers that operate on expressions, they return HTML code A template can be (pre)-compiled and must be executed with a context in order to return the final HTML fragment
  • 104. Example of built-in helper It renders the block if its argument is not equal to false, Ā undefined, Ā null, Ā [] Ā  If / Else <div Ā class="entryā€œ> Ā  <h1>{{title}}</h1> Ā  {{#if Ā author}} Ā  Ā <h2>By Ā {{firstName}} Ā {{lastName}}</h2> Ā  {{#else}} Ā  Ā <h2>Unknown Ā author</h1> Ā  Ā  {{/if}} Ā  </div> Ā  Ā  { Ā title: Ā "My Ā first Ā post!", Ā  Ā  Ā  Ā  Ā author: Ā undefined Ā } Ā  } Ā  Ā  <div Ā class="entryā€œ> Ā  <h1>My Ā first Ā post!</h1> Ā  <h2>Unknown Ā author</h2> Ā  </div> Ā  Ā 
  • 105. Roadmap •  Introduction •  Backbone •  Require JS •  Handlebars •  Combining backbone, Require, and Handlebars
  • 106. Combining Backbone, Require, and Handlebars Handlebars templates can be seen as special Require modules So we can have the following: •  a separate HTML5 file for each template •  a Backbone view can have a dependency to each template •  the template can be executed by using a JSON object of the Backbone model as context
  • 107. Example Dependency to template HTML file It contains a string Compiled template Execution of the template
  • 108. How I structure my mobile web apps
  • 109. I implemented all best practices and advices in this presentation in a generic app template available here: https://github.com/iivanoo/cordovaboilerplate
  • 110. Towards automation… Towards a Collaborative Framework for the Design and Development of Data- Intensive Mobile Applications. Mirco Franzago, Ivano Malavolta, Henry Muccini. Proceedings of the 1st ACM International Conference on Mobile Software Engineering and Systems, June 2-3, 2014 Hyderabad, India
  • 112. + 39 380 70 21 600 Contact Ivano Malavolta | Gran Sasso Science Institute iivanoo [email protected] www.ivanomalavolta.com