SlideShare une entreprise Scribd logo
1  sur  72
Building great mobile web
apps: Some things you
might want to know
     By Shwetank Dixit, Opera Software
about me
Web Evangelist, Opera Developer
Relations Team

Member, W3C Mobile Web for Social
Development Group

Member, W3C Web Education
Community Group

twitter.com/shwetank
email: shwetankd@opera.com
“All the pieces matter...”
           - Lester Freemon, The Wire
We’re (mainly) going to
talk about slick web apps
on full featured mobile
browsers
But first spare a thought
for the low powered
devices which can’t run a
full featured browser
But first spare a thought
for the low powered
devices which can’t run a
full featured browser
      IT CONSTITUTES A MAJORITY OF THE MOBILE WEB
              (AS OF RIGHT NOW AND THE NEAR TERM)
The most important thing
to know about the mobile
web...
Just one Web
Smartphone browsers != Webkit
Furthermore, which webkit
are you talking about?
 READ PPK’S ARTICLE TITLED “THERE IS NO WEBKIT ON MOBILE”
It’s ok if the same site
looks different in different
devices
As long as they are optimized for it.
But if you do have a
different mobile site...
ALWAYS provide a link to switch back to the
desktop version.
W3C Mobile Web Best
Practices guidelines
RTFG
Offline webapps
with html5
Offline Apps: Storing the
files need to run offline
CACHE MANIFEST
      #this is a comment.

           style.css
           script.js
          index.htm



contents of the manifest file.
<html manifest=”demo.manifest”>


Linking the manifest file to the html page.
CACHE MANIFEST
              #this is a comment.

                   style.css
                   script.js
                  index.htm

                  NETWORK:
               dynamicpage.php



The NETWORK: section header bypasses the cache
CACHE MANIFEST
                 #this is a comment.

                      style.css
                      script.js
                     index.htm

                     FALLBACK:
               original.jpg backup.jpg


If a file can’t load, then the FALLBACK: section header
specifies which files to load as a backup in their place
ALWAYS KEEPING AN UPDATED CACHE


                          �
�
Offline Apps: Storing the
data for offline use
Storage: Web Storage
The problem with cookies
Unreliable
No programmatic APIs to manipulate it
Not structured

Most of important of all ...
Small file size, so very limited data can be
stored.
Web Storage
Session Storage and Local Storage
localStorage.setItem(yourkey,
yourvalue); // Store the value

var item = localStorage.getItem
(yourkey); // Retrieve the value and assign
it to a variable
Example of using Web Storage to store and
retrieve values in the browser’s local storage
With this, even if you close the browser and re-open the page again, the values should
still load properly.
You can store images (and
more) with localStorage
                 ....BUT DON”T.
Automatically save entered
form info locally
in case page crashes or closes, person can
resume from where he left off
STORE USER DATA OFFLINE
         PERIODICALLY


�
�
Or...
You could save only when you detect a new
keystroke (or a minimum number of them)
Gotcha
Two tabs updating the same value
Storage events
Know if some other page has changed the
value or not
GET NEW VALUE IF ITS BEEN CHANGED
         IN PARALLEL TAB
�
�
�
Gotcha
Using a free hosting service - Don’t use local
storage with it if they store users accounts
on different directories.

e.g, freehosting.com/user1
and freehosting.com/user2
Other storage
options
- IndexedDB (Limited browser support currently)
- WebSQL (Standard in impasse. Limited desktop browser
support but nice mobile browser support.)
Further reading
Run your web apps offline with HTML5 Application Cache: http://dev.opera.com/
articles/view/offline-applications-html5-appcache/

Web Storage: easier, more powerful client-side data storage: http://dev.opera.com/
articles/view/web-storage/

Taking your web apps offline: A tale of Web Storage, Application Cache and WebSQL:
http://dev.opera.com/articles/view/taking-your-web-apps-offline-web-storage-
appcache-websql/
Media queries
�




Provide different styles to different
resolutions using media queries
Traditionally, mobile browsers provide a
‘zoomed out’ view, and then you can tap in
Viewport meta tag
Allows you to set the zooming level
Scaling constraints
<meta name="viewport"
content="width=device-width,
maximum-scale=2, minimum-scale=0.5">
Disable user scaling
<meta name="viewport"
content="width=device-width,
user-scalable=no">
In Opera, you can use CSS
to control viewport
For example...

@-o-viewport {
  width: device-width;
  max-zoom: 2;
  min-zoom: 0.5;
}
Geolocation
Find yourself
“These are my thoughts in
a well published format”
-The early web
“Here is what we can all
do together”
- “Web 2.0”
“This is what I’m thinking”
- Facebook, twitter and other social tools
“This is where I’m at”
- The next step
Think of the possibilities
Augmented reality
Geofencing
location aware advertising
...more
//Check if browser supports W3C Geolocation API
if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition
(successFunction, errorFunction);
} else {
    alert('Geolocation not supported.');
}
Sample code for running geolocation, if
available
function successFunction(position) {
  var lat = position.coords.latitude;
  var long = position.coords.longitude;
  alert('Your latitude is :'+lat+' and longitude is '+long);
}

Determining the position
function errorFunction(position){
 if (pos.PositionError == 1){
 alert('It seems you have decided not to share your
location');
 }
 if (pos.PositionError == 2){
 alert('The location could not be determined by the
browser. Try to reload the page to try again');
 }

Handling errors
SEE FULL LIST OF ERRORS ON THE SPEC
watchPosition()
Same as getCurrentPosition() but fires
whenever there is a change in location.

Sometimes its better to use this than the
former.
Accuracy
Scarily accurate in some places,
amusingly inaccurate in others.

DO NOT rely on it.
Provide fallbacks, and ways to enter location
info manually (like zipcode)
The Geolocation Spec
May be up for a bit of a change in the future
Further reading
How to use the W3C Geolocation API: http://dev.opera.com/articles/view/how-to-use-
the-w3c-geolocation-api/

Use the Geolocation API in Webapps: http://goo.gl/EBVYt
A sneak peak
Device Orientation
Access to gyroscope, accelerometer info etc
Access gyroscope info
window.addEventListener
("deviceorientation", function(event) {

      // process event.alpha, event.beta and
event.gamma

   }, true);
Access accelerometer info
window.addEventListener("devicemotion",
function(event) {

     // Process event.acceleration

   }, true);
Another sneak peak
Check for access
if (navigator.getUserMedia){
 	 navigator.getUserMedia('video', v_success,
v_error);
 }

else{
 	 not_supported();
 }
Check for access
var video_element = document.querySelector('video');
...
...
function v_success(stream){
 	 video_element.src = stream;
}
Use camera + <video> +
<canvas> for new tricks
var button = document.querySelector('#button');
button.addEventListener('click',snapshot, false);
...
...
function snapshot(){
 	 var c = document.querySelector('canvas');
 	 var ctx = c.getContext('2d');
 	 var cw = c.clientWidth;
 	 var ch = c.clientHeight;
 	 ctx.drawImage(video_element, 0, 0, cw, ch);
 }
Keep in mind
WebRTC spec (containing getUserMedia) is
still in flux. Not a mature standard yet.
Download the Opera
Mobile labs build with
device orientation and
getUserMedia support
Download from here: http://my.opera.com/core/blog/2011/03/23/webcam-
orientation-preview
Read up on
Dev.opera.com
Cheers!
More questions? Ask me now or contact me
at:
shwetankd@opera.com
or, twitter.com/shwetank

Contenu connexe

Tendances

Practical webRTC - from API to Solution - webRTC Summit 2014 @ NYC
Practical webRTC - from API to Solution - webRTC Summit 2014 @ NYCPractical webRTC - from API to Solution - webRTC Summit 2014 @ NYC
Practical webRTC - from API to Solution - webRTC Summit 2014 @ NYC
Alexandre Gouaillard
 

Tendances (20)

Introduction to WebRTC
Introduction to WebRTCIntroduction to WebRTC
Introduction to WebRTC
 
Practical webRTC - from API to Solution - webRTC Summit 2014 @ NYC
Practical webRTC - from API to Solution - webRTC Summit 2014 @ NYCPractical webRTC - from API to Solution - webRTC Summit 2014 @ NYC
Practical webRTC - from API to Solution - webRTC Summit 2014 @ NYC
 
Webrtc
WebrtcWebrtc
Webrtc
 
KITE Network Instrumentation: Advanced WebRTC Testing
KITE Network Instrumentation: Advanced WebRTC TestingKITE Network Instrumentation: Advanced WebRTC Testing
KITE Network Instrumentation: Advanced WebRTC Testing
 
Real-Time Communication Testing Evolution with WebRTC
Real-Time Communication Testing Evolution with WebRTCReal-Time Communication Testing Evolution with WebRTC
Real-Time Communication Testing Evolution with WebRTC
 
WebRTC Seminar Report
WebRTC  Seminar ReportWebRTC  Seminar Report
WebRTC Seminar Report
 
Introduction To Webrtc
Introduction To WebrtcIntroduction To Webrtc
Introduction To Webrtc
 
Webrtc plugins for Desktop Browsers
Webrtc plugins for Desktop BrowsersWebrtc plugins for Desktop Browsers
Webrtc plugins for Desktop Browsers
 
WebRTC DataChannels demystified
WebRTC DataChannels demystifiedWebRTC DataChannels demystified
WebRTC DataChannels demystified
 
WebRTC Status Update - 2017Q2
WebRTC Status Update - 2017Q2WebRTC Status Update - 2017Q2
WebRTC Status Update - 2017Q2
 
DevCon5 (July 2014) - Intro to WebRTC
DevCon5 (July 2014) - Intro to WebRTCDevCon5 (July 2014) - Intro to WebRTC
DevCon5 (July 2014) - Intro to WebRTC
 
WebRTC Check-in (from WebRTC Boston 6)
WebRTC Check-in (from WebRTC Boston 6)WebRTC Check-in (from WebRTC Boston 6)
WebRTC Check-in (from WebRTC Boston 6)
 
DevCon5 (July 2014) - Acision SDK
DevCon5 (July 2014) - Acision SDKDevCon5 (July 2014) - Acision SDK
DevCon5 (July 2014) - Acision SDK
 
Quality Assurance for WebRTC Services
Quality Assurance for WebRTC ServicesQuality Assurance for WebRTC Services
Quality Assurance for WebRTC Services
 
WebRTC presentation
WebRTC presentationWebRTC presentation
WebRTC presentation
 
DevCon 5 (December 2013) - WebRTC & WebSockets
DevCon 5 (December 2013) - WebRTC & WebSocketsDevCon 5 (December 2013) - WebRTC & WebSockets
DevCon 5 (December 2013) - WebRTC & WebSockets
 
Getting started with WebRTC
Getting started with WebRTCGetting started with WebRTC
Getting started with WebRTC
 
WebRTC beyond Audio and Video
WebRTC beyond Audio and Video  WebRTC beyond Audio and Video
WebRTC beyond Audio and Video
 
Asterisk World (January 2014) - Taking Enterprise Telephony into the Web World
Asterisk World (January 2014) - Taking Enterprise Telephony into the Web WorldAsterisk World (January 2014) - Taking Enterprise Telephony into the Web World
Asterisk World (January 2014) - Taking Enterprise Telephony into the Web World
 
Janus conf'19: janus client side
Janus conf'19:  janus client sideJanus conf'19:  janus client side
Janus conf'19: janus client side
 

En vedette

Inspiring news trends and innovations 2013
Inspiring news trends and innovations 2013Inspiring news trends and innovations 2013
Inspiring news trends and innovations 2013
Alain Mbouche
 
Centrust Savings Bank - Business Card
Centrust Savings Bank - Business CardCentrust Savings Bank - Business Card
Centrust Savings Bank - Business Card
Boris O. Jaynes
 
Plan de desarrollo municipal de aldana nariño
Plan de desarrollo municipal de aldana nariñoPlan de desarrollo municipal de aldana nariño
Plan de desarrollo municipal de aldana nariño
alvelasco
 
Mysteriousmilitary facts (2)
Mysteriousmilitary facts (2)Mysteriousmilitary facts (2)
Mysteriousmilitary facts (2)
hindujudaic
 
HTML5 APIs - native multimedia support and beyond - University of Leeds 05.05...
HTML5 APIs - native multimedia support and beyond - University of Leeds 05.05...HTML5 APIs - native multimedia support and beyond - University of Leeds 05.05...
HTML5 APIs - native multimedia support and beyond - University of Leeds 05.05...
Patrick Lauke
 
openMIC barcamp 11.02.2010
openMIC barcamp 11.02.2010openMIC barcamp 11.02.2010
openMIC barcamp 11.02.2010
Patrick Lauke
 

En vedette (20)

Rosa (2n A)
Rosa (2n A)Rosa (2n A)
Rosa (2n A)
 
Manel V.
Manel V.Manel V.
Manel V.
 
Inspiring news trends and innovations 2013
Inspiring news trends and innovations 2013Inspiring news trends and innovations 2013
Inspiring news trends and innovations 2013
 
556
556556
556
 
Taming the tiger - pnwphp
Taming the tiger - pnwphpTaming the tiger - pnwphp
Taming the tiger - pnwphp
 
Que diferença faz uma estação......
Que diferença faz uma estação......Que diferença faz uma estação......
Que diferença faz uma estação......
 
Centrust Savings Bank - Business Card
Centrust Savings Bank - Business CardCentrust Savings Bank - Business Card
Centrust Savings Bank - Business Card
 
Thais C. (2n A)
Thais C. (2n A)Thais C. (2n A)
Thais C. (2n A)
 
Sc oct 2015 the hottest free sourcing tools available dean da costa
Sc oct 2015 the hottest free sourcing tools available   dean da costaSc oct 2015 the hottest free sourcing tools available   dean da costa
Sc oct 2015 the hottest free sourcing tools available dean da costa
 
FKC
FKC FKC
FKC
 
Plan de desarrollo municipal de aldana nariño
Plan de desarrollo municipal de aldana nariñoPlan de desarrollo municipal de aldana nariño
Plan de desarrollo municipal de aldana nariño
 
Mysteriousmilitary facts (2)
Mysteriousmilitary facts (2)Mysteriousmilitary facts (2)
Mysteriousmilitary facts (2)
 
Habilidades sociales
Habilidades socialesHabilidades sociales
Habilidades sociales
 
Ai Lead Scoring And Lead Rating
Ai Lead Scoring And Lead RatingAi Lead Scoring And Lead Rating
Ai Lead Scoring And Lead Rating
 
W3C/Webkit test integration presentation
W3C/Webkit test integration presentationW3C/Webkit test integration presentation
W3C/Webkit test integration presentation
 
HTML5 APIs - native multimedia support and beyond - University of Leeds 05.05...
HTML5 APIs - native multimedia support and beyond - University of Leeds 05.05...HTML5 APIs - native multimedia support and beyond - University of Leeds 05.05...
HTML5 APIs - native multimedia support and beyond - University of Leeds 05.05...
 
Open Annotation Collaboration Briefing
Open Annotation Collaboration BriefingOpen Annotation Collaboration Briefing
Open Annotation Collaboration Briefing
 
openMIC barcamp 11.02.2010
openMIC barcamp 11.02.2010openMIC barcamp 11.02.2010
openMIC barcamp 11.02.2010
 
Node.js, le pavé dans la mare
Node.js, le pavé dans la mareNode.js, le pavé dans la mare
Node.js, le pavé dans la mare
 
HTML5 and XHTML2
HTML5 and XHTML2HTML5 and XHTML2
HTML5 and XHTML2
 

Similaire à Building great mobile apps: Somethings you might want to know

Html5 and beyond the next generation of mobile web applications - Touch Tou...
Html5 and beyond   the next generation of mobile web applications - Touch Tou...Html5 and beyond   the next generation of mobile web applications - Touch Tou...
Html5 and beyond the next generation of mobile web applications - Touch Tou...
RIA RUI Society
 
Web app and more
Web app and moreWeb app and more
Web app and more
faming su
 

Similaire à Building great mobile apps: Somethings you might want to know (20)

Html5 and beyond the next generation of mobile web applications - Touch Tou...
Html5 and beyond   the next generation of mobile web applications - Touch Tou...Html5 and beyond   the next generation of mobile web applications - Touch Tou...
Html5 and beyond the next generation of mobile web applications - Touch Tou...
 
Building WebApp with HTML5
Building WebApp with HTML5Building WebApp with HTML5
Building WebApp with HTML5
 
your browser, my storage
your browser, my storageyour browser, my storage
your browser, my storage
 
Web Apps and more
Web Apps and moreWeb Apps and more
Web Apps and more
 
Web app and more
Web app and moreWeb app and more
Web app and more
 
Creating Rajanikant Powered Site
Creating Rajanikant Powered SiteCreating Rajanikant Powered Site
Creating Rajanikant Powered Site
 
Developing Java Web Applications
Developing Java Web ApplicationsDeveloping Java Web Applications
Developing Java Web Applications
 
Ror caching
Ror cachingRor caching
Ror caching
 
Bruce lawson-over-the-air
Bruce lawson-over-the-airBruce lawson-over-the-air
Bruce lawson-over-the-air
 
Taking Web Applications Offline
Taking Web Applications OfflineTaking Web Applications Offline
Taking Web Applications Offline
 
Taking your Web App for a walk
Taking your Web App for a walkTaking your Web App for a walk
Taking your Web App for a walk
 
Fame
FameFame
Fame
 
your browser, your storage
your browser, your storageyour browser, your storage
your browser, your storage
 
Html5
Html5Html5
Html5
 
Local storage
Local storageLocal storage
Local storage
 
Week 05 Web, App and Javascript_Brandon, S.H. Wu
Week 05 Web, App and Javascript_Brandon, S.H. WuWeek 05 Web, App and Javascript_Brandon, S.H. Wu
Week 05 Web, App and Javascript_Brandon, S.H. Wu
 
Building Isomorphic Apps (JSConf.Asia 2014)
Building Isomorphic Apps (JSConf.Asia 2014)Building Isomorphic Apps (JSConf.Asia 2014)
Building Isomorphic Apps (JSConf.Asia 2014)
 
Always on! ... or not?
Always on! ... or not?Always on! ... or not?
Always on! ... or not?
 
Angular js mobile jsday 2014 - Verona 14 may
Angular js mobile   jsday 2014 - Verona 14 mayAngular js mobile   jsday 2014 - Verona 14 may
Angular js mobile jsday 2014 - Verona 14 may
 
Always on! Or not?
Always on! Or not?Always on! Or not?
Always on! Or not?
 

Dernier

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Dernier (20)

AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 

Building great mobile apps: Somethings you might want to know