Web versus Native: round 1!

Web versus native
Chris Mills // Mozilla cmills@mozilla.com // @chrisdavidmills
don’t worry about taking notes:
๏ These slides are all at slideshare.net/chrisdavidmills
๏ developer.mozilla.org
๏ @chrisdavidmills
๏ cmills@mozilla.com
๏ #mdn irc channel on mozilla irc
๏ dev-mdc@lists.mozilla.org mailing list
๏ heavy metal drummer turned web nerd
๏ tech writer @ mozilla
๏ web tinkerer (HTML, CSS, JS)
๏ accessibility whiner
๏ educator
who am i?
mdn!!
what’s the

problem?
web versus native, the age-old struggle
the usual arguments
native is better?
๏ faster?
๏ offine?
๏ more integrated, consistent experience?
๏ better developer ecosystem/tools?
๏ more secure?
the usual arguments
๏ web apps accessing other apps?
๏ web apps accessing

camera

contacts

SMS/MMs

dialler??
app ecosystem
Firefox os
We have this firefox os thing!
๏ open source project:

everyone can get involved
๏ everything runs on the gecko engine
๏ Gaia: UI and suite of default apps
๏ Gonk: the underlying kernel/haL
installable apps
not a new phenomenon, but...
๏ pretty recent concept for web technologies
๏ manifest file defines app (manifest.webapp)
๏ installation controlled by app installation and management apis
{
"version": "0.1",
"name": "To-do alarms",
"description": "My awesome open web app",
"launch_path": "/index.html",
"icons": {
"128": "/img/icon-128.png"
},
"developer": {
"name": "Chris Mills",
"url": "http://yourawesomeapp.com"
},
"locales": {
"es": {
"description": "Su nueva aplicación impresionante Open Web",
"developer": {
"url": "http://yourawesomeapp.com"
}
}, manifest example
var manifest_url = location.href.substring(0,
location.href.lastIndexOf("/")) + "/manifest.webapp";
function install() {
// install the app
var install = navigator.mozApps.install(manifest_url);
install.onsuccess = function(data) {
// App is installed, do something if you like
};
install.onerror = function() {
// App wasn't installed, info is in
// install.error.name
alert(install.error.name);
};
};
installation example
app types
Apps can be:
๏ hosted: just like a normal web site, but with a manifest and install
functionality
๏ packaged: zipped up, hosted somewhere (like the firefox
marketplace), verified
app payments
you can charge money for web apps
๏ payments api uses payment providers like bango
๏ receipt verification to make sure payments are completed
๏ in-app payments also available (fxPay, mozpay)
web runtime
web rt allows app installation on other platforms
๏ apk factory for android apps, which include native api equivalents
where possible
๏ similar native wrappers for desktop platforms
๏ firefox marketplace/Firefox will generate these
developer

experience
developer experience
we want to give the web a first class development experience,
alongside native ecosystems:
๏ documentation
๏ developer tools
๏ frameworks, templates, libraries
documentation
announce new things, provide useful references, give
recommendations:
๏ hacks blog
๏ mdn (app center)
developer tools
developer tools
๏ firefox’s standard toolbox
๏ app manager webide
๏ remote debugging using connect...
๏ you can run gaia on the desktop with firefox mulet
๏ node-firefox
webide
frameworks and libraries
ready made code to make development easier
๏ mortar app templates
๏ Web components
๏ firefox os boilerplate app
๏ phonegap support for firefox os
๏ and of course, ember, angular, backbone, yadda yadda
(device) apis
make it work on the web*...
*ok, ok, using web technologies!
apis!!!
we want to control everything using web technology
๏ apis to handle access to device hardware, system functions, etc.
๏ security handled by permissions, in the manifest
api permissions
different apis have different permission levels:
๏ common apis can be accessed by any app
๏ privileged apis can only be used in packaged, verified apps (e.g.
contacts, camera, device storage)
๏ internal (certified) apis can only be used by vendor-installed apps
(e.g. sms, dialer, bluetooth)
var pick = new MozActivity({
name: "pick",
data: {
type: ["image/png", "image/jpg", "image/jpeg"]


}
});
web activities (intents)
web activities
pick.onsuccess = function () {
// Create image and set the returned blob as the src
var img = document.createElement("img");
img.src = window.URL.createObjectURL(this.result.blob);
// Present that image in your app
var imagePresenter = document.querySelector("#image-presenter");
imagePresenter.appendChild(img);
};
pick.onerror = function () {
// If an error occurred or the user canceled the activity
alert("Can't view the image!");
};
web activities
var img = '/to-do-notifications/img/icon-128.png';
var text = 'HEY! Your task "' + title + '" is now overdue.';
var notification = new Notification('To do list', { body: text, icon:
img });
notification
window.navigator.vibrate(200); // vibrate for 200ms
window.navigator.vibrate([100,30,100,30,100,200,200,30,200,30,200,200,10
0,30,100,30,100]); // Vibrate 'SOS' in Morse.
vibration
window.addEventListener('devicelight', function(event) {
var html = document.getElementsByTagName('html')[0];
if (event.value < 50) {
html.classList.add('darklight');
html.classList.remove('brightlight');
} else {
html.classList.add('brightlight');
html.classList.remove('darklight');
}
});
ambient light events
ambient light events
ambient light events
window.addEventListener("deviceorientation", handleOrientation, true);
function handleOrientation(event) {
var alpha = event.alpha;
var beta = event.beta;
var gamma = event.gamma;
// Do stuff with the new orientation data
}
device orientation
device orientation
alpha
betagamma
getusermedia
var constraints = { audio: true };
var onSuccess = function(stream) {
// do stuff with your media stream
};
var onError = function(err) {
console.log('The following error occurred: ' + err);
}
navigator.getUserMedia(constraints, onSuccess, onError);
mediarecorder
var mediaRecorder = new MediaRecorder(stream);
record.onclick = function() {
mediaRecorder.start();
}
stop.onclick = function() {
mediaRecorder.stop();
}
mediaRecorder.ondataavailable = function(e) {
var audio = document.createElement('audio');
audio.setAttribute('controls', '');
var audioURL = window.URL.createObjectURL(e.data);
audio.src = audioURL;
}
nfc
function ndefDiscoveredHandler(activity) {
var data = activity.source.data;
var tag = navigator.mozNfc.getNFCTag(data.sessionToken);
console.log(tag instanceof MozNFCTag); // should print true
}
var request = tag.readNDEF();
request.onsuccess = function() {
var ndefRecords = request.result; // ndefRecords should be an array of
MozNDEFRecord.
};
nfc
navigator.mozNfc.onpeerready = function (evt) {
var peer = navigator.mozNfc.getNFCPeer(evt.detail);
console.log(peer instanceof MozNFCPeer); // should print true;
};
var request = peer.sendNDEF(ndefRecords);
var request = peer.sendFile(blob);
Web speech API
๏ work in progress
๏ doing speech synthesis and recognition in javascript, client-side
privileged/certified api examples
๏ CAmERA
๏ FMradio
๏ bluetooth
๏ sms
๏ telephony
๏ Wifimanager
advanced communication
sometimes the web model can be a pain
๏ same origin security
๏ cors/systemxhr
๏ broadcast channels/message channels
๏ request response model
๏ web sockets
๏ webrtc
broadcast channels
// Connection to a broadcast channel
var bc = new BroadcastChannel(“test_channel");
// Example of sending of a very simple message
bc.postMessage("This is a test message.”);
// Exemple of a simple event handler that only
// logs the event to the console
bc.onmessage = function (e) { console.log(e); }
// Disconnect the channel
bc.close()
channel messaging
var channel = new MessageChannel();
var ifr = document.querySelector('iframe');
var otherWindow = ifr.contentWindow;
ifr.addEventListener("load", iframeLoaded, false);
function iframeLoaded() {
otherWindow.postMessage('Hello from the main page!', '*',
[channel.port2]);
}
channel.port1.onmessage = handleMessage;
function handleMessage(e) {
para.innerHTML = e.data;
}
offline apps
no connection = no experience
offline is hard
The main problems are as follows:
๏ offline data storage
๏ offline asset storage
๏ detecting available network and reacting to it
offline data
this is not so bad:
๏ indexeddb, localstorage, websql
๏ (datastore api for firefox os)
๏ there’s something available in most browsers
๏ localforage library polyfills across browsers
offline apps/assets
offline app assets are a pain
๏ firefox os packaged apps are installed and available offline
๏ this doesn’t help the web at large
๏ we had app cache…
…this had promise...
CACHE MANIFEST
# v1
CACHE:
css/app.css
index.html
js/main.js
js/lib/require.js
...but was actually evil.
detecting network state
network state is also a pain
๏ Network information API is pretty unreliable
๏ you could check xhr responses, but this isn’t ideal
hello service workers!
This could be the answer…
service workers are coming
๏ proxy servers that sits between your app and the browser
๏ intercepting network requests and customising responses
๏ does similar things to app cache (plus a lot more)
๏ granular control over actions
register service worker
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw-test/sw.js', {
scope: '/*'
}).then(function(sw) {
// registration worked
console.log('Registration succeeded.');
}).catch(function() {
// registration failed
console.log('Registration failed.');
});
}
install service worker
this.addEventListener('install', function(event) {
event.waitUntil(
caches.create('v1').then(function(cache) {
return cache.add(
'/sw-test/',
'/sw-test/index.html',
'/sw-test/style.css',
'/sw-test/app.js',
'/sw-test/image-list.js',
'/sw-test/star-wars-logo.jpg'
// etc.
);
})
);
});
custom request responses
this.addEventListener('fetch', function(event) {
event.respondWith(
caches.match(event.request).catch(function() {
return event.default();
return caches.get('v1').then(function(cache) {
cache.add(event.request);
});
}).catch(function() {
return caches.match('/sw-test/gallery/myLittleVader.jpg');
})
);
});
performance

enhancers
performance enhancers
๏ web workers
๏ web audio api
๏ asm.js
๏ emscripten
web workers
web workers
๏ run scripts in a background thread
๏ don’t block the main thread execution
web audio api
web audio api
๏ precise control and manipulation of audio
๏ add effects to audio
๏ split and merge audio streams
๏ spatialise audio
๏ create audio visualisations
audiochannels
audiochannels api
๏ set different audio to play in different importance hierarchy
channels
๏ react to headphones being plugged in or unplugged
๏ more important audio can continue to play in the background, e.g.
music player audio
asm.js
asm.js
๏ a very efficient low-level subset of JS
๏ suitable for ahead-of-time optimizing compilation
๏ Unity3d now has asm.js/WebGL support

emscripten
emscripteN
๏ an LLVM to javascript compiler (well, asm.js, specifically)
๏ compile c++ (and others) into JS and run it on the web
๏ = “very fast shit” ™
๏ See emscripten.org
Web versus Native: round 1!
Web versus Native: round 1!
resources
๏ MDN: developer.mozilla.org/
๏ demos on github.com/mdn
๏ hacks blog: hacks.mozilla.org
๏ look up localforage - polyfill for indexeddb/websql/localstorage
๏ simplewebrtc.com - simple webrtc library
๏ emscripten.org - try quakejs.com
๏ asmjs.org
๏ mzl.la/openwebapps - give us your feedback on what the web
platform needs!
thanks for

listening!!
slideshare.net/chrisdavidmills cmills@mozilla.com // @chrisdavidmills
1 of 69

Recommended

APIs, now and in the future by
APIs, now and in the futureAPIs, now and in the future
APIs, now and in the futureChris Mills
1.3K views59 slides
APIs for modern web apps by
APIs for modern web appsAPIs for modern web apps
APIs for modern web appsChris Mills
827 views59 slides
Empowering the "mobile web" by
Empowering the "mobile web"Empowering the "mobile web"
Empowering the "mobile web"Chris Mills
1.1K views60 slides
High Performance JavaScript - WebDirections USA 2010 by
High Performance JavaScript - WebDirections USA 2010High Performance JavaScript - WebDirections USA 2010
High Performance JavaScript - WebDirections USA 2010Nicholas Zakas
59.7K views105 slides
High Performance JavaScript - jQuery Conference SF Bay Area 2010 by
High Performance JavaScript - jQuery Conference SF Bay Area 2010High Performance JavaScript - jQuery Conference SF Bay Area 2010
High Performance JavaScript - jQuery Conference SF Bay Area 2010Nicholas Zakas
47.7K views103 slides
Instant and offline apps with Service Worker by
Instant and offline apps with Service WorkerInstant and offline apps with Service Worker
Instant and offline apps with Service WorkerChang W. Doh
856 views82 slides

More Related Content

What's hot

High Performance JavaScript (YUIConf 2010) by
High Performance JavaScript (YUIConf 2010)High Performance JavaScript (YUIConf 2010)
High Performance JavaScript (YUIConf 2010)Nicholas Zakas
61.8K views148 slides
HTML5 Web Workers-unleashed by
HTML5 Web Workers-unleashedHTML5 Web Workers-unleashed
HTML5 Web Workers-unleashedPeter Lubbers
5.5K views81 slides
An Introduction to webOS by
An Introduction to webOSAn Introduction to webOS
An Introduction to webOSKevin Decker
1.9K views30 slides
High Performance JavaScript (Amazon DevCon 2011) by
High Performance JavaScript (Amazon DevCon 2011)High Performance JavaScript (Amazon DevCon 2011)
High Performance JavaScript (Amazon DevCon 2011)Nicholas Zakas
4.6K views155 slides
Getting Started with HTML 5 Web workers by
Getting Started with HTML 5 Web workersGetting Started with HTML 5 Web workers
Getting Started with HTML 5 Web workersFlumes
1.7K views33 slides
Web workers by
Web workersWeb workers
Web workersSurbhi Mathur
2.8K views26 slides

What's hot(19)

High Performance JavaScript (YUIConf 2010) by Nicholas Zakas
High Performance JavaScript (YUIConf 2010)High Performance JavaScript (YUIConf 2010)
High Performance JavaScript (YUIConf 2010)
Nicholas Zakas61.8K views
HTML5 Web Workers-unleashed by Peter Lubbers
HTML5 Web Workers-unleashedHTML5 Web Workers-unleashed
HTML5 Web Workers-unleashed
Peter Lubbers5.5K views
An Introduction to webOS by Kevin Decker
An Introduction to webOSAn Introduction to webOS
An Introduction to webOS
Kevin Decker1.9K views
High Performance JavaScript (Amazon DevCon 2011) by Nicholas Zakas
High Performance JavaScript (Amazon DevCon 2011)High Performance JavaScript (Amazon DevCon 2011)
High Performance JavaScript (Amazon DevCon 2011)
Nicholas Zakas4.6K views
Getting Started with HTML 5 Web workers by Flumes
Getting Started with HTML 5 Web workersGetting Started with HTML 5 Web workers
Getting Started with HTML 5 Web workers
Flumes1.7K views
Keeping the frontend under control with Symfony and Webpack by Ignacio Martín
Keeping the frontend under control with Symfony and WebpackKeeping the frontend under control with Symfony and Webpack
Keeping the frontend under control with Symfony and Webpack
Ignacio Martín6.4K views
React & The Art of Managing Complexity by Ryan Anklam
React &  The Art of Managing ComplexityReact &  The Art of Managing Complexity
React & The Art of Managing Complexity
Ryan Anklam1.3K views
Building Cross Platform Apps with Electron by Chris Ward
Building Cross Platform Apps with ElectronBuilding Cross Platform Apps with Electron
Building Cross Platform Apps with Electron
Chris Ward435 views
Learning from the Best jQuery Plugins by Marc Grabanski
Learning from the Best jQuery PluginsLearning from the Best jQuery Plugins
Learning from the Best jQuery Plugins
Marc Grabanski47.6K views
Chrome enchanted 2015 by Chang W. Doh
Chrome enchanted 2015Chrome enchanted 2015
Chrome enchanted 2015
Chang W. Doh2.1K views
Disrupting the application eco system with progressive web applications by Chris Love
Disrupting the application eco system with progressive web applicationsDisrupting the application eco system with progressive web applications
Disrupting the application eco system with progressive web applications
Chris Love1.4K views
Node JS Express : Steps to Create Restful Web App by Edureka!
Node JS Express : Steps to Create Restful Web AppNode JS Express : Steps to Create Restful Web App
Node JS Express : Steps to Create Restful Web App
Edureka!3.2K views
Don't Over-React - just use Vue! by Raymond Camden
Don't Over-React - just use Vue!Don't Over-React - just use Vue!
Don't Over-React - just use Vue!
Raymond Camden2.6K views
High Performance JavaScript - Fronteers 2010 by Nicholas Zakas
High Performance JavaScript - Fronteers 2010High Performance JavaScript - Fronteers 2010
High Performance JavaScript - Fronteers 2010
Nicholas Zakas4.2K views
PWA 與 Service Worker by Anna Su
PWA 與 Service WorkerPWA 與 Service Worker
PWA 與 Service Worker
Anna Su4.8K views
Introduction to JQuery, ASP.NET MVC and Silverlight by Peter Gfader
Introduction to JQuery, ASP.NET MVC and SilverlightIntroduction to JQuery, ASP.NET MVC and Silverlight
Introduction to JQuery, ASP.NET MVC and Silverlight
Peter Gfader7.9K views

Viewers also liked

Lapset ensin - Kainutlaatuinen tapa edistää lasten ja perheiden hyvinvointia by
Lapset ensin - Kainutlaatuinen tapa edistää lasten ja perheiden hyvinvointia Lapset ensin - Kainutlaatuinen tapa edistää lasten ja perheiden hyvinvointia
Lapset ensin - Kainutlaatuinen tapa edistää lasten ja perheiden hyvinvointia THL
324 views12 slides
Guerrilla education by
Guerrilla educationGuerrilla education
Guerrilla educationChris Mills
41.3K views37 slides
Evaluation question 4 by
Evaluation question 4Evaluation question 4
Evaluation question 4bethwhitehead95
225 views10 slides
Catching the marketing bug with Steven Campbell by
Catching the marketing bug with Steven CampbellCatching the marketing bug with Steven Campbell
Catching the marketing bug with Steven CampbellBay Area Consultants Network
436 views40 slides
Costa Rica Real Estate Opportunities tour, bargains for both self directed IR... by
Costa Rica Real Estate Opportunities tour, bargains for both self directed IR...Costa Rica Real Estate Opportunities tour, bargains for both self directed IR...
Costa Rica Real Estate Opportunities tour, bargains for both self directed IR...Pacific Lots of Costa Rica
1.8K views70 slides
Reforma Hacendaria by
Reforma HacendariaReforma Hacendaria
Reforma HacendariaUNID
432 views11 slides

Viewers also liked(20)

Lapset ensin - Kainutlaatuinen tapa edistää lasten ja perheiden hyvinvointia by THL
Lapset ensin - Kainutlaatuinen tapa edistää lasten ja perheiden hyvinvointia Lapset ensin - Kainutlaatuinen tapa edistää lasten ja perheiden hyvinvointia
Lapset ensin - Kainutlaatuinen tapa edistää lasten ja perheiden hyvinvointia
THL324 views
Guerrilla education by Chris Mills
Guerrilla educationGuerrilla education
Guerrilla education
Chris Mills41.3K views
Costa Rica Real Estate Opportunities tour, bargains for both self directed IR... by Pacific Lots of Costa Rica
Costa Rica Real Estate Opportunities tour, bargains for both self directed IR...Costa Rica Real Estate Opportunities tour, bargains for both self directed IR...
Costa Rica Real Estate Opportunities tour, bargains for both self directed IR...
Reforma Hacendaria by UNID
Reforma HacendariaReforma Hacendaria
Reforma Hacendaria
UNID432 views
презентация современные требования к выпускнику детского сада by romisflasher
презентация современные требования к выпускнику детского садапрезентация современные требования к выпускнику детского сада
презентация современные требования к выпускнику детского сада
romisflasher599 views
Las posibilidades del_blog_como_elemento_de_apoyo_y_refuerzo_en_el_aprendizaje by Priscy Ayala
Las posibilidades del_blog_como_elemento_de_apoyo_y_refuerzo_en_el_aprendizajeLas posibilidades del_blog_como_elemento_de_apoyo_y_refuerzo_en_el_aprendizaje
Las posibilidades del_blog_como_elemento_de_apoyo_y_refuerzo_en_el_aprendizaje
Priscy Ayala324 views
Obrade Dieste Jessica Rial- Natalia Carril 4ºA by guest80ebf5f
Obrade Dieste Jessica Rial- Natalia Carril  4ºAObrade Dieste Jessica Rial- Natalia Carril  4ºA
Obrade Dieste Jessica Rial- Natalia Carril 4ºA
guest80ebf5f266 views
GAMENEXT-SUMMIT 2015 티저(KR) by GAMENEXT Works
GAMENEXT-SUMMIT 2015 티저(KR)GAMENEXT-SUMMIT 2015 티저(KR)
GAMENEXT-SUMMIT 2015 티저(KR)
GAMENEXT Works3K views
Introducción a la programación y la informática. Tema 6 by Andres Garcia Garcia
Introducción a la programación y la informática. Tema 6Introducción a la programación y la informática. Tema 6
Introducción a la programación y la informática. Tema 6
Publicación de mi árticulo en revista evalúa de la cc.mm. corrientes novedo... by as o
Publicación de mi árticulo en revista evalúa de la cc.mm.   corrientes novedo...Publicación de mi árticulo en revista evalúa de la cc.mm.   corrientes novedo...
Publicación de mi árticulo en revista evalúa de la cc.mm. corrientes novedo...
as o697 views
Lakewood WA crime stats April 2010 by Walter Neary
Lakewood WA crime stats April 2010Lakewood WA crime stats April 2010
Lakewood WA crime stats April 2010
Walter Neary380 views
[GAMENEXT] 스타트업 소개 - 인앱인 by GAMENEXT Works
[GAMENEXT] 스타트업 소개 - 인앱인 [GAMENEXT] 스타트업 소개 - 인앱인
[GAMENEXT] 스타트업 소개 - 인앱인
GAMENEXT Works2K views
Alan reyna salazar by alanreyna00
Alan reyna salazarAlan reyna salazar
Alan reyna salazar
alanreyna001.4K views
Smoking by csvp
SmokingSmoking
Smoking
csvp228 views
Doing the open source thingy by Wiebe Elsinga
Doing the open source thingyDoing the open source thingy
Doing the open source thingy
Wiebe Elsinga933 views

Similar to Web versus Native: round 1!

Empowering the “Mobile Web” with Chris Mills by
Empowering the “Mobile Web” with Chris MillsEmpowering the “Mobile Web” with Chris Mills
Empowering the “Mobile Web” with Chris MillsFITC
1.4K views60 slides
Empowering the Mobile Web - Mills by
Empowering the Mobile Web - MillsEmpowering the Mobile Web - Mills
Empowering the Mobile Web - MillsCodemotion
603 views60 slides
Electron - cross platform desktop applications made easy by
Electron - cross platform desktop applications made easyElectron - cross platform desktop applications made easy
Electron - cross platform desktop applications made easyUlrich Krause
787 views92 slides
Mobile Device APIs by
Mobile Device APIsMobile Device APIs
Mobile Device APIsJames Pearce
30.6K views67 slides
Intro To webOS by
Intro To webOSIntro To webOS
Intro To webOSfpatton
7.8K views77 slides
Web APIs & Apps - Mozilla by
Web APIs & Apps - MozillaWeb APIs & Apps - Mozilla
Web APIs & Apps - MozillaRobert Nyman
17.6K views116 slides

Similar to Web versus Native: round 1!(20)

Empowering the “Mobile Web” with Chris Mills by FITC
Empowering the “Mobile Web” with Chris MillsEmpowering the “Mobile Web” with Chris Mills
Empowering the “Mobile Web” with Chris Mills
FITC1.4K views
Empowering the Mobile Web - Mills by Codemotion
Empowering the Mobile Web - MillsEmpowering the Mobile Web - Mills
Empowering the Mobile Web - Mills
Codemotion603 views
Electron - cross platform desktop applications made easy by Ulrich Krause
Electron - cross platform desktop applications made easyElectron - cross platform desktop applications made easy
Electron - cross platform desktop applications made easy
Ulrich Krause787 views
Mobile Device APIs by James Pearce
Mobile Device APIsMobile Device APIs
Mobile Device APIs
James Pearce30.6K views
Intro To webOS by fpatton
Intro To webOSIntro To webOS
Intro To webOS
fpatton7.8K views
Web APIs & Apps - Mozilla by Robert Nyman
Web APIs & Apps - MozillaWeb APIs & Apps - Mozilla
Web APIs & Apps - Mozilla
Robert Nyman17.6K views
WebAPIs & Apps - Mozilla London by Robert Nyman
WebAPIs & Apps - Mozilla LondonWebAPIs & Apps - Mozilla London
WebAPIs & Apps - Mozilla London
Robert Nyman30.7K views
Fixing the mobile web - Internet World Romania by Christian Heilmann
Fixing the mobile web - Internet World RomaniaFixing the mobile web - Internet World Romania
Fixing the mobile web - Internet World Romania
Christian Heilmann11K views
Bringing the open web and APIs to mobile devices with Firefox OS - Whisky W... by Robert Nyman
 	Bringing the open web and APIs to mobile devices with Firefox OS - Whisky W... 	Bringing the open web and APIs to mobile devices with Firefox OS - Whisky W...
Bringing the open web and APIs to mobile devices with Firefox OS - Whisky W...
Robert Nyman7K views
Electron Firenze 2020: Linux, Windows o MacOS? by Denny Biasiolli
Electron Firenze 2020: Linux, Windows o MacOS?Electron Firenze 2020: Linux, Windows o MacOS?
Electron Firenze 2020: Linux, Windows o MacOS?
Denny Biasiolli89 views
[Devoxx Morocco 2015] Apache Cordova In Action by Hazem Saleh
[Devoxx Morocco 2015] Apache Cordova In Action[Devoxx Morocco 2015] Apache Cordova In Action
[Devoxx Morocco 2015] Apache Cordova In Action
Hazem Saleh893 views
openMIC barcamp 11.02.2010 by Patrick Lauke
openMIC barcamp 11.02.2010openMIC barcamp 11.02.2010
openMIC barcamp 11.02.2010
Patrick Lauke875 views
Bringing the Open Web & APIs to 
mobile devices with Firefox OS - Geek Meet by Robert Nyman
Bringing the Open Web & APIs to 
mobile devices with Firefox OS - Geek MeetBringing the Open Web & APIs to 
mobile devices with Firefox OS - Geek Meet
Bringing the Open Web & APIs to 
mobile devices with Firefox OS - Geek Meet
Robert Nyman17.3K views
JavaScript Libraries: The Big Picture by Simon Willison
JavaScript Libraries: The Big PictureJavaScript Libraries: The Big Picture
JavaScript Libraries: The Big Picture
Simon Willison4K views
Firefox OS workshop, Colombia by Robert Nyman
Firefox OS workshop, ColombiaFirefox OS workshop, Colombia
Firefox OS workshop, Colombia
Robert Nyman9.1K views
Ideal Deployment In .NET World by Dima Pasko
Ideal Deployment In .NET WorldIdeal Deployment In .NET World
Ideal Deployment In .NET World
Dima Pasko1.7K views
How to implement camera recording for USB webcam or IP camera in C#.NET by Ozeki Informatics Ltd.
How to implement camera recording for USB webcam or IP camera in C#.NETHow to implement camera recording for USB webcam or IP camera in C#.NET
How to implement camera recording for USB webcam or IP camera in C#.NET

More from Chris Mills

More efficient, usable web by
More efficient, usable webMore efficient, usable web
More efficient, usable webChris Mills
179 views57 slides
Feedback handling, community wrangling, panhandlin’ by
Feedback handling, community wrangling, panhandlin’Feedback handling, community wrangling, panhandlin’
Feedback handling, community wrangling, panhandlin’Chris Mills
540 views50 slides
BrazilJS MDN by
BrazilJS MDNBrazilJS MDN
BrazilJS MDNChris Mills
756 views25 slides
Documentation and publishing by
Documentation and publishingDocumentation and publishing
Documentation and publishingChris Mills
1.1K views107 slides
MDN is easy! by
MDN is easy!MDN is easy!
MDN is easy!Chris Mills
1.5K views46 slides
Getting rid of images with CSS by
Getting rid of images with CSSGetting rid of images with CSS
Getting rid of images with CSSChris Mills
2.4K views91 slides

More from Chris Mills(20)

More efficient, usable web by Chris Mills
More efficient, usable webMore efficient, usable web
More efficient, usable web
Chris Mills179 views
Feedback handling, community wrangling, panhandlin’ by Chris Mills
Feedback handling, community wrangling, panhandlin’Feedback handling, community wrangling, panhandlin’
Feedback handling, community wrangling, panhandlin’
Chris Mills540 views
Documentation and publishing by Chris Mills
Documentation and publishingDocumentation and publishing
Documentation and publishing
Chris Mills1.1K views
Getting rid of images with CSS by Chris Mills
Getting rid of images with CSSGetting rid of images with CSS
Getting rid of images with CSS
Chris Mills2.4K views
Laying out the future by Chris Mills
Laying out the futureLaying out the future
Laying out the future
Chris Mills1.4K views
Accessibility doesn't exist by Chris Mills
Accessibility doesn't existAccessibility doesn't exist
Accessibility doesn't exist
Chris Mills795 views
Responsive web design standards? by Chris Mills
Responsive web design standards?Responsive web design standards?
Responsive web design standards?
Chris Mills4.6K views
Adapt! Media queries and viewport by Chris Mills
Adapt! Media queries and viewportAdapt! Media queries and viewport
Adapt! Media queries and viewport
Chris Mills2.7K views
Adapt and respond: keeping responsive into the future by Chris Mills
Adapt and respond: keeping responsive into the futureAdapt and respond: keeping responsive into the future
Adapt and respond: keeping responsive into the future
Chris Mills2.3K views
Angels versus demons: balancing shiny and inclusive by Chris Mills
Angels versus demons: balancing shiny and inclusiveAngels versus demons: balancing shiny and inclusive
Angels versus demons: balancing shiny and inclusive
Chris Mills3.3K views
HTML5 and CSS3: does now really mean now? by Chris Mills
HTML5 and CSS3: does now really mean now?HTML5 and CSS3: does now really mean now?
HTML5 and CSS3: does now really mean now?
Chris Mills3.6K views
The W3C and the web design ecosystem by Chris Mills
The W3C and the web design ecosystemThe W3C and the web design ecosystem
The W3C and the web design ecosystem
Chris Mills1.4K views
HTML5 Pearson preso by Chris Mills
HTML5 Pearson presoHTML5 Pearson preso
HTML5 Pearson preso
Chris Mills1.4K views
Brave new world of HTML5 by Chris Mills
Brave new world of HTML5Brave new world of HTML5
Brave new world of HTML5
Chris Mills1.4K views
Inclusive design: real accessibility for everyone by Chris Mills
Inclusive design: real accessibility for everyoneInclusive design: real accessibility for everyone
Inclusive design: real accessibility for everyone
Chris Mills1.6K views
The web standards gentleman: a matter of (evolving) standards) by Chris Mills
The web standards gentleman: a matter of (evolving) standards)The web standards gentleman: a matter of (evolving) standards)
The web standards gentleman: a matter of (evolving) standards)
Chris Mills5.4K views
Optimizing content for the "mobile web" by Chris Mills
Optimizing content for the "mobile web"Optimizing content for the "mobile web"
Optimizing content for the "mobile web"
Chris Mills1.1K views

Web versus Native: round 1!

  • 1. Web versus native Chris Mills // Mozilla cmills@mozilla.com // @chrisdavidmills
  • 2. don’t worry about taking notes: ๏ These slides are all at slideshare.net/chrisdavidmills ๏ developer.mozilla.org ๏ @chrisdavidmills ๏ cmills@mozilla.com ๏ #mdn irc channel on mozilla irc ๏ dev-mdc@lists.mozilla.org mailing list
  • 3. ๏ heavy metal drummer turned web nerd ๏ tech writer @ mozilla ๏ web tinkerer (HTML, CSS, JS) ๏ accessibility whiner ๏ educator who am i? mdn!!
  • 5. web versus native, the age-old struggle
  • 6. the usual arguments native is better? ๏ faster? ๏ offine? ๏ more integrated, consistent experience? ๏ better developer ecosystem/tools? ๏ more secure?
  • 7. the usual arguments ๏ web apps accessing other apps? ๏ web apps accessing
 camera
 contacts
 SMS/MMs
 dialler??
  • 9. Firefox os We have this firefox os thing! ๏ open source project:
 everyone can get involved ๏ everything runs on the gecko engine ๏ Gaia: UI and suite of default apps ๏ Gonk: the underlying kernel/haL
  • 10. installable apps not a new phenomenon, but... ๏ pretty recent concept for web technologies ๏ manifest file defines app (manifest.webapp) ๏ installation controlled by app installation and management apis
  • 11. { "version": "0.1", "name": "To-do alarms", "description": "My awesome open web app", "launch_path": "/index.html", "icons": { "128": "/img/icon-128.png" }, "developer": { "name": "Chris Mills", "url": "http://yourawesomeapp.com" }, "locales": { "es": { "description": "Su nueva aplicación impresionante Open Web", "developer": { "url": "http://yourawesomeapp.com" } }, manifest example
  • 12. var manifest_url = location.href.substring(0, location.href.lastIndexOf("/")) + "/manifest.webapp"; function install() { // install the app var install = navigator.mozApps.install(manifest_url); install.onsuccess = function(data) { // App is installed, do something if you like }; install.onerror = function() { // App wasn't installed, info is in // install.error.name alert(install.error.name); }; }; installation example
  • 13. app types Apps can be: ๏ hosted: just like a normal web site, but with a manifest and install functionality ๏ packaged: zipped up, hosted somewhere (like the firefox marketplace), verified
  • 14. app payments you can charge money for web apps ๏ payments api uses payment providers like bango ๏ receipt verification to make sure payments are completed ๏ in-app payments also available (fxPay, mozpay)
  • 15. web runtime web rt allows app installation on other platforms ๏ apk factory for android apps, which include native api equivalents where possible ๏ similar native wrappers for desktop platforms ๏ firefox marketplace/Firefox will generate these
  • 17. developer experience we want to give the web a first class development experience, alongside native ecosystems: ๏ documentation ๏ developer tools ๏ frameworks, templates, libraries
  • 18. documentation announce new things, provide useful references, give recommendations: ๏ hacks blog ๏ mdn (app center)
  • 19. developer tools developer tools ๏ firefox’s standard toolbox ๏ app manager webide ๏ remote debugging using connect... ๏ you can run gaia on the desktop with firefox mulet ๏ node-firefox
  • 21. frameworks and libraries ready made code to make development easier ๏ mortar app templates ๏ Web components ๏ firefox os boilerplate app ๏ phonegap support for firefox os ๏ and of course, ember, angular, backbone, yadda yadda
  • 23. make it work on the web*...
  • 24. *ok, ok, using web technologies!
  • 25. apis!!! we want to control everything using web technology ๏ apis to handle access to device hardware, system functions, etc. ๏ security handled by permissions, in the manifest
  • 26. api permissions different apis have different permission levels: ๏ common apis can be accessed by any app ๏ privileged apis can only be used in packaged, verified apps (e.g. contacts, camera, device storage) ๏ internal (certified) apis can only be used by vendor-installed apps (e.g. sms, dialer, bluetooth)
  • 27. var pick = new MozActivity({ name: "pick", data: { type: ["image/png", "image/jpg", "image/jpeg"] 
 } }); web activities (intents)
  • 29. pick.onsuccess = function () { // Create image and set the returned blob as the src var img = document.createElement("img"); img.src = window.URL.createObjectURL(this.result.blob); // Present that image in your app var imagePresenter = document.querySelector("#image-presenter"); imagePresenter.appendChild(img); }; pick.onerror = function () { // If an error occurred or the user canceled the activity alert("Can't view the image!"); }; web activities
  • 30. var img = '/to-do-notifications/img/icon-128.png'; var text = 'HEY! Your task "' + title + '" is now overdue.'; var notification = new Notification('To do list', { body: text, icon: img }); notification
  • 31. window.navigator.vibrate(200); // vibrate for 200ms window.navigator.vibrate([100,30,100,30,100,200,200,30,200,30,200,200,10 0,30,100,30,100]); // Vibrate 'SOS' in Morse. vibration
  • 32. window.addEventListener('devicelight', function(event) { var html = document.getElementsByTagName('html')[0]; if (event.value < 50) { html.classList.add('darklight'); html.classList.remove('brightlight'); } else { html.classList.add('brightlight'); html.classList.remove('darklight'); } }); ambient light events
  • 35. window.addEventListener("deviceorientation", handleOrientation, true); function handleOrientation(event) { var alpha = event.alpha; var beta = event.beta; var gamma = event.gamma; // Do stuff with the new orientation data } device orientation
  • 37. getusermedia var constraints = { audio: true }; var onSuccess = function(stream) { // do stuff with your media stream }; var onError = function(err) { console.log('The following error occurred: ' + err); } navigator.getUserMedia(constraints, onSuccess, onError);
  • 38. mediarecorder var mediaRecorder = new MediaRecorder(stream); record.onclick = function() { mediaRecorder.start(); } stop.onclick = function() { mediaRecorder.stop(); } mediaRecorder.ondataavailable = function(e) { var audio = document.createElement('audio'); audio.setAttribute('controls', ''); var audioURL = window.URL.createObjectURL(e.data); audio.src = audioURL; }
  • 39. nfc function ndefDiscoveredHandler(activity) { var data = activity.source.data; var tag = navigator.mozNfc.getNFCTag(data.sessionToken); console.log(tag instanceof MozNFCTag); // should print true } var request = tag.readNDEF(); request.onsuccess = function() { var ndefRecords = request.result; // ndefRecords should be an array of MozNDEFRecord. };
  • 40. nfc navigator.mozNfc.onpeerready = function (evt) { var peer = navigator.mozNfc.getNFCPeer(evt.detail); console.log(peer instanceof MozNFCPeer); // should print true; }; var request = peer.sendNDEF(ndefRecords); var request = peer.sendFile(blob);
  • 41. Web speech API ๏ work in progress ๏ doing speech synthesis and recognition in javascript, client-side
  • 42. privileged/certified api examples ๏ CAmERA ๏ FMradio ๏ bluetooth ๏ sms ๏ telephony ๏ Wifimanager
  • 43. advanced communication sometimes the web model can be a pain ๏ same origin security ๏ cors/systemxhr ๏ broadcast channels/message channels ๏ request response model ๏ web sockets ๏ webrtc
  • 44. broadcast channels // Connection to a broadcast channel var bc = new BroadcastChannel(“test_channel"); // Example of sending of a very simple message bc.postMessage("This is a test message.”); // Exemple of a simple event handler that only // logs the event to the console bc.onmessage = function (e) { console.log(e); } // Disconnect the channel bc.close()
  • 45. channel messaging var channel = new MessageChannel(); var ifr = document.querySelector('iframe'); var otherWindow = ifr.contentWindow; ifr.addEventListener("load", iframeLoaded, false); function iframeLoaded() { otherWindow.postMessage('Hello from the main page!', '*', [channel.port2]); } channel.port1.onmessage = handleMessage; function handleMessage(e) { para.innerHTML = e.data; }
  • 47. no connection = no experience
  • 48. offline is hard The main problems are as follows: ๏ offline data storage ๏ offline asset storage ๏ detecting available network and reacting to it
  • 49. offline data this is not so bad: ๏ indexeddb, localstorage, websql ๏ (datastore api for firefox os) ๏ there’s something available in most browsers ๏ localforage library polyfills across browsers
  • 50. offline apps/assets offline app assets are a pain ๏ firefox os packaged apps are installed and available offline ๏ this doesn’t help the web at large ๏ we had app cache…
  • 51. …this had promise... CACHE MANIFEST # v1 CACHE: css/app.css index.html js/main.js js/lib/require.js
  • 53. detecting network state network state is also a pain ๏ Network information API is pretty unreliable ๏ you could check xhr responses, but this isn’t ideal
  • 55. This could be the answer… service workers are coming ๏ proxy servers that sits between your app and the browser ๏ intercepting network requests and customising responses ๏ does similar things to app cache (plus a lot more) ๏ granular control over actions
  • 56. register service worker if ('serviceWorker' in navigator) { navigator.serviceWorker.register('/sw-test/sw.js', { scope: '/*' }).then(function(sw) { // registration worked console.log('Registration succeeded.'); }).catch(function() { // registration failed console.log('Registration failed.'); }); }
  • 57. install service worker this.addEventListener('install', function(event) { event.waitUntil( caches.create('v1').then(function(cache) { return cache.add( '/sw-test/', '/sw-test/index.html', '/sw-test/style.css', '/sw-test/app.js', '/sw-test/image-list.js', '/sw-test/star-wars-logo.jpg' // etc. ); }) ); });
  • 58. custom request responses this.addEventListener('fetch', function(event) { event.respondWith( caches.match(event.request).catch(function() { return event.default(); return caches.get('v1').then(function(cache) { cache.add(event.request); }); }).catch(function() { return caches.match('/sw-test/gallery/myLittleVader.jpg'); }) ); });
  • 60. performance enhancers ๏ web workers ๏ web audio api ๏ asm.js ๏ emscripten
  • 61. web workers web workers ๏ run scripts in a background thread ๏ don’t block the main thread execution
  • 62. web audio api web audio api ๏ precise control and manipulation of audio ๏ add effects to audio ๏ split and merge audio streams ๏ spatialise audio ๏ create audio visualisations
  • 63. audiochannels audiochannels api ๏ set different audio to play in different importance hierarchy channels ๏ react to headphones being plugged in or unplugged ๏ more important audio can continue to play in the background, e.g. music player audio
  • 64. asm.js asm.js ๏ a very efficient low-level subset of JS ๏ suitable for ahead-of-time optimizing compilation ๏ Unity3d now has asm.js/WebGL support

  • 65. emscripten emscripteN ๏ an LLVM to javascript compiler (well, asm.js, specifically) ๏ compile c++ (and others) into JS and run it on the web ๏ = “very fast shit” ™ ๏ See emscripten.org
  • 68. resources ๏ MDN: developer.mozilla.org/ ๏ demos on github.com/mdn ๏ hacks blog: hacks.mozilla.org ๏ look up localforage - polyfill for indexeddb/websql/localstorage ๏ simplewebrtc.com - simple webrtc library ๏ emscripten.org - try quakejs.com ๏ asmjs.org ๏ mzl.la/openwebapps - give us your feedback on what the web platform needs!