SlideShare une entreprise Scribd logo
1  sur  12
PhoneGap Development Best
        Practices
                                 Fil Maj
                        Nitobi Software
Overview
•   Fast cross-platform prototyping, how to do it.
•   Templating.
•   Offline strategies.
•   Persistent storage.
•   File API.
•   XUI overview.
•   When *not* to use PhoneGap.
Cross-platform
   Prototyping with
      PhoneGap
• Main advantage of PhoneGap is you
  can reuse your web application
  source code across platforms.
• A good, quick approach is to write
  one set of assets and ‘tweak’ across
  platforms.
• HTML and CSS can be, more-or-less,
  written once.
    – Highly recommend writing
      percentage-based styles initially,
      and down the road tweaking on a
      per-platform basis.
    – Combined with a <meta
      name=“viewport”> tag (which tells
      the browser the size of the screen
      it’s being viewed in), results are
      good.
Cross-platform Prototyping with
              PhoneGap, cont.
• JavaScript is tougher, mainly due to weak BlackBerry support.
  However, latest XUI works on BlackBerry! More on this in a bit.
    – A process that has brought a measure of success for us is to first
      determine which platforms to target, and then build your mobile
      application logic in a JavaScript framework that works with the ‘lowest
      common denominator’ platform. JavaScript frameworks are your
      friends (jQuery, MooTools, XUI, etc.).
    – Existing software development best practices apply. Use a layered and
      modular approach for your JavaScript.
    – MVC (model-view-controller) paradigm is great for prototyping, as you
      can revisit and, if need be, recode particular modules of your app as
      you iterate.
        • Model = PhoneGap JS API + offline storage/cache (+ Lawnchair?)
        • Controller = JavaScript
        • View = HTML + CSS
Templating
•   Common web development practice used to encapsulate view components of an app.
•   As you work on an app, you notice repeatable HTML/CSS patterns that come up. Don’t copy+paste
    it!
     –   Encapsulate the view pattern HTML aka ‘template’ in a JavaScript string:
         var tweetTemplate = „<div class=“tweet”>{USER} said {MESSAGE}</div>‟;
     –   Create a JavaScript function that takes the template and replaces the tokens (placeholders) with actual data:
         function tweetify(data) {
           var tweets = document.createElement(„div‟);
           var newHTML = „‟;
           for (var i =0; i<data.length;i++) {
               var tweet = tweetTemplate.replace(/{USER}/,data[i].user);
               tweet = j.replace(/{MESSAGE}/,data[i].message);
               newHTML += tweet;
           }
           tweets.innerHTML += tweet;
           document.getElementById(„content‟).appendChild(tweets);
         }
•   This approach follows the MVC paradigm and is a good example of separation of concerns. Also
    easy to read, easy to extend and reusable.
•   John Resig blogged about this, he doesn’t use regex but instead he uses:
    tweetTemplate.split(“match”).join(“replace”).
    It’s quicker apparently: http://ejohn.org/blog/javascript-micro-templating/
Offline Strategies
• Inherently, mobile devices will not be networked
  all the time. Bad coverage, on the plane, no data
  plan, etc.
• Extremely important for every application to take
  this into account, especially for iPhone. It is a
  hard criteria in Apple’s App review process (to see
  how gracefully an app handles lack of internet
  connection).
• PhoneGap offers reachability API, example:
  http://github.com/phonegap/mobile-
  spec/blob/master/tests/network.tests.js
Persistent Storage
• iPhone has SQLite, Safari implements the HTML 5 spec.
  Tutorial: http://phonegap.pbworks.com/Adding-SQL-
  Database-support-to-your-iPhone-App
   – Note: each page in a PhoneGap app can have only a single
     database object open, and its maximum store size is 5
     megabytes (2 MB on Android, but you can change this to suit
     your needs). Take this into account when using a single-page
     approach to a PhoneGap app (more on this later).
• BlackBerry has ‘persistent storage’ – a giant key/value
  store. Code exists to access this, but we haven’t figured out
  how to fit it into the PhoneGap API. Somehow it needs to
  align with the other platforms. Ask me
  (filip.maj@nitobi.com) for it if you want it!
File API
• You can read/write files from PhoneGap too.
  Implementations available at our own local repositories
  (not yet part of the spec / public API).
   – http://github.com/purplecabbage/phonegap-
     iphone/blob/master/PhoneGapLib/javascripts/core/file.js
   – BlackBerry native code is present but needs a JavaScript
     wrapper.
   – Android File I/O got revamped recently.
   – Also: Mobile Spec tests are NOT up to date and platforms are
     fragmented on the implementation of this feature. It needs
     some work!
• Work is ongoing to line our file API up with the HTML 5
  specification: http://www.w3.org/TR/2009/WD-FileAPI-
  20091117/#dfn-empty
XUI Overview
• Another (!) JavaScript framework: xuijs.com
• This one’s special, though: specifically designed for
  mobile devices.
• Biggest win: small footprint (~6-10kb).
• Inspired by jQuery with a very similar syntax.
• Works on iPhone, Android, Symbian, Palm and… drum
  roll… BlackBerry too! But you need to build it
  specifically for BlackBerry; the output script files are
  labelled as core, more or bb – the bb file is for
  BlackBerry.
• Is the recommended framework to use with
  PhoneGap.
PhoneGap Performance Tips
• For small apps, use a single HTML page.
   – Use JavaScript to show/hide page elements based on user
     interaction instead of linking to a separate page.
   – Especially important for BlackBerry, since each new page
     request forces the device to encode requested assets into
     base64 on-the-fly.
• Obfuscate / crunch your JavaScript before release.
   – Devices only reserve a bit of memory for JavaScript
     interpreters for the browser. If your JavaScript is small
     enough, it won’t be necessary for the browser to
     constantly page your scripts in/out of the browser
     memory. iPhone, for example, has 25kb of memory
     reserved for JavaScript parsing.
PhoneGap Limitations
• As important as knowing how to use
  PhoneGap is also knowing when NOT to use it.
  – Complex games, intensive graphics. Use OpenGL
    for that, not PhoneGap.
  – For slower phones (not iPhone, not Nexus One,
    not Xperia X10), PhoneGap apps using the latest
    interactive Google Maps APIs tend to be slow.
    Static maps OK, though.
Questions/Comments?

Contenu connexe

Tendances

Mobile applications for SharePoint using HTML5
Mobile applications for SharePoint using HTML5Mobile applications for SharePoint using HTML5
Mobile applications for SharePoint using HTML5Christian Heindel
 
Vue storefront London PWA meetup
Vue storefront London PWA meetupVue storefront London PWA meetup
Vue storefront London PWA meetupFilip Rakowski
 
Internship - Bootstrap
Internship - BootstrapInternship - Bootstrap
Internship - Bootstraptanay29
 
Flash: A call for sanity
Flash: A call for sanityFlash: A call for sanity
Flash: A call for sanityAndrew Dobson
 
HTML5 - The Future in a Flash
HTML5 - The Future in a FlashHTML5 - The Future in a Flash
HTML5 - The Future in a FlashRick Snailum
 
JWC 2015 - Mobile apps development for Joomla!
JWC 2015 - Mobile apps development for Joomla!JWC 2015 - Mobile apps development for Joomla!
JWC 2015 - Mobile apps development for Joomla!Extly Extensions - JoomGap
 
Gears and HTML 5 @media Ajax London 2008
Gears and HTML 5 @media Ajax London 2008Gears and HTML 5 @media Ajax London 2008
Gears and HTML 5 @media Ajax London 2008dion
 
Joomla REST API - JoomlaDay Bangkok 2014
Joomla REST API - JoomlaDay Bangkok 2014Joomla REST API - JoomlaDay Bangkok 2014
Joomla REST API - JoomlaDay Bangkok 2014Ashwin Date
 
Aspect oriented programming
Aspect oriented programmingAspect oriented programming
Aspect oriented programmingRobert MacLean
 
Developing cross platform mobile applications with phone gap for windows phone
Developing cross platform mobile applications with phone gap for windows phoneDeveloping cross platform mobile applications with phone gap for windows phone
Developing cross platform mobile applications with phone gap for windows phoneColin Eberhardt
 
Beyond responsive design - UI for the modern web application
Beyond responsive design - UI for the modern web applicationBeyond responsive design - UI for the modern web application
Beyond responsive design - UI for the modern web applicationPete Smith
 
Drupal Views Event Presentation
Drupal Views Event PresentationDrupal Views Event Presentation
Drupal Views Event PresentationRyan Cross
 
Something drupal this way comes
Something drupal this way comesSomething drupal this way comes
Something drupal this way comesMark Casias
 
Full Stack Web Development
Full Stack Web DevelopmentFull Stack Web Development
Full Stack Web DevelopmentSWAGATHCHOWDARY1
 

Tendances (20)

Mobile applications for SharePoint using HTML5
Mobile applications for SharePoint using HTML5Mobile applications for SharePoint using HTML5
Mobile applications for SharePoint using HTML5
 
Vue storefront London PWA meetup
Vue storefront London PWA meetupVue storefront London PWA meetup
Vue storefront London PWA meetup
 
Maintainable design
Maintainable designMaintainable design
Maintainable design
 
PhoneGap
PhoneGapPhoneGap
PhoneGap
 
Internship - Bootstrap
Internship - BootstrapInternship - Bootstrap
Internship - Bootstrap
 
Windows 8
Windows 8Windows 8
Windows 8
 
Flash: A call for sanity
Flash: A call for sanityFlash: A call for sanity
Flash: A call for sanity
 
HTML5 - The Future in a Flash
HTML5 - The Future in a FlashHTML5 - The Future in a Flash
HTML5 - The Future in a Flash
 
JWC 2015 - Mobile apps development for Joomla!
JWC 2015 - Mobile apps development for Joomla!JWC 2015 - Mobile apps development for Joomla!
JWC 2015 - Mobile apps development for Joomla!
 
Gears and HTML 5 @media Ajax London 2008
Gears and HTML 5 @media Ajax London 2008Gears and HTML 5 @media Ajax London 2008
Gears and HTML 5 @media Ajax London 2008
 
Joomla REST API - JoomlaDay Bangkok 2014
Joomla REST API - JoomlaDay Bangkok 2014Joomla REST API - JoomlaDay Bangkok 2014
Joomla REST API - JoomlaDay Bangkok 2014
 
Aspect oriented programming
Aspect oriented programmingAspect oriented programming
Aspect oriented programming
 
WebMatrix
WebMatrixWebMatrix
WebMatrix
 
Developing cross platform mobile applications with phone gap for windows phone
Developing cross platform mobile applications with phone gap for windows phoneDeveloping cross platform mobile applications with phone gap for windows phone
Developing cross platform mobile applications with phone gap for windows phone
 
Beyond responsive design - UI for the modern web application
Beyond responsive design - UI for the modern web applicationBeyond responsive design - UI for the modern web application
Beyond responsive design - UI for the modern web application
 
PhoneGap
PhoneGapPhoneGap
PhoneGap
 
Drupal Views Event Presentation
Drupal Views Event PresentationDrupal Views Event Presentation
Drupal Views Event Presentation
 
Something drupal this way comes
Something drupal this way comesSomething drupal this way comes
Something drupal this way comes
 
Joomla REST API
Joomla REST APIJoomla REST API
Joomla REST API
 
Full Stack Web Development
Full Stack Web DevelopmentFull Stack Web Development
Full Stack Web Development
 

En vedette

Напольный газовый котел Buderus Logano G334-94 WS
Напольный газовый котел Buderus Logano G334-94 WSНапольный газовый котел Buderus Logano G334-94 WS
Напольный газовый котел Buderus Logano G334-94 WSAl Maks
 
Informe empleados
Informe empleadosInforme empleados
Informe empleadoskode99
 
Tokina Lens Katalog
Tokina Lens KatalogTokina Lens Katalog
Tokina Lens Katalogreproset
 
Untrash summit presentation 1
Untrash summit presentation 1Untrash summit presentation 1
Untrash summit presentation 1scswa
 
Газовый напольный котел Bosch ZBS 30/210 S solar
Газовый напольный котел Bosch ZBS 30/210 S solarГазовый напольный котел Bosch ZBS 30/210 S solar
Газовый напольный котел Bosch ZBS 30/210 S solarAl Maks
 
Sennheiser Hear Real Sound Experience "Vany Hilman Ghifary"
Sennheiser Hear Real Sound Experience "Vany Hilman Ghifary"Sennheiser Hear Real Sound Experience "Vany Hilman Ghifary"
Sennheiser Hear Real Sound Experience "Vany Hilman Ghifary"Vany Hilman Ghifary
 
Gasteizko irteera 2B MARRUBI
Gasteizko irteera 2B MARRUBIGasteizko irteera 2B MARRUBI
Gasteizko irteera 2B MARRUBIarbelar
 
Maude’s life in pictures final-as PDF
Maude’s life in pictures final-as PDFMaude’s life in pictures final-as PDF
Maude’s life in pictures final-as PDFCatherine McLean
 
Свеча зажигания NGK
Свеча зажигания NGKСвеча зажигания NGK
Свеча зажигания NGKAl Maks
 
Psicologia del color
Psicologia del colorPsicologia del color
Psicologia del colorNicolas Pino
 
Formulario producto
Formulario productoFormulario producto
Formulario productokode99
 
Jx webinar csr-materiality-brand-v1-condensed
Jx webinar csr-materiality-brand-v1-condensedJx webinar csr-materiality-brand-v1-condensed
Jx webinar csr-materiality-brand-v1-condensedAdam Garfunkel
 

En vedette (20)

Напольный газовый котел Buderus Logano G334-94 WS
Напольный газовый котел Buderus Logano G334-94 WSНапольный газовый котел Buderus Logano G334-94 WS
Напольный газовый котел Buderus Logano G334-94 WS
 
Ref IT
Ref ITRef IT
Ref IT
 
Informe empleados
Informe empleadosInforme empleados
Informe empleados
 
An approach for knowledge-driven product, process and resource mappings for a...
An approach for knowledge-driven product, process and resource mappings for a...An approach for knowledge-driven product, process and resource mappings for a...
An approach for knowledge-driven product, process and resource mappings for a...
 
Tokina Lens Katalog
Tokina Lens KatalogTokina Lens Katalog
Tokina Lens Katalog
 
Untrash summit presentation 1
Untrash summit presentation 1Untrash summit presentation 1
Untrash summit presentation 1
 
theQuiz(7);
theQuiz(7);theQuiz(7);
theQuiz(7);
 
Kemahiran Komunikasi
Kemahiran KomunikasiKemahiran Komunikasi
Kemahiran Komunikasi
 
Газовый напольный котел Bosch ZBS 30/210 S solar
Газовый напольный котел Bosch ZBS 30/210 S solarГазовый напольный котел Bosch ZBS 30/210 S solar
Газовый напольный котел Bosch ZBS 30/210 S solar
 
Sennheiser Hear Real Sound Experience "Vany Hilman Ghifary"
Sennheiser Hear Real Sound Experience "Vany Hilman Ghifary"Sennheiser Hear Real Sound Experience "Vany Hilman Ghifary"
Sennheiser Hear Real Sound Experience "Vany Hilman Ghifary"
 
Gasteizko irteera 2B MARRUBI
Gasteizko irteera 2B MARRUBIGasteizko irteera 2B MARRUBI
Gasteizko irteera 2B MARRUBI
 
Maude’s life in pictures final-as PDF
Maude’s life in pictures final-as PDFMaude’s life in pictures final-as PDF
Maude’s life in pictures final-as PDF
 
Свеча зажигания NGK
Свеча зажигания NGKСвеча зажигания NGK
Свеча зажигания NGK
 
Álbumnubes
ÁlbumnubesÁlbumnubes
Álbumnubes
 
Psicologia del color
Psicologia del colorPsicologia del color
Psicologia del color
 
Thank you 2015
Thank you 2015Thank you 2015
Thank you 2015
 
3D Previews
3D Previews3D Previews
3D Previews
 
Formulario producto
Formulario productoFormulario producto
Formulario producto
 
Facebook Stats
Facebook StatsFacebook Stats
Facebook Stats
 
Jx webinar csr-materiality-brand-v1-condensed
Jx webinar csr-materiality-brand-v1-condensedJx webinar csr-materiality-brand-v1-condensed
Jx webinar csr-materiality-brand-v1-condensed
 

Similaire à Seattle bestpractices2010

Developing Windows Phone 8 apps using PhoneGap
Developing Windows Phone 8 apps using PhoneGapDeveloping Windows Phone 8 apps using PhoneGap
Developing Windows Phone 8 apps using PhoneGapAmar Mesic
 
Getting started with PhoneGap
Getting started with PhoneGapGetting started with PhoneGap
Getting started with PhoneGapMihai Corlan
 
Anatomy of an HTML 5 mobile web app
Anatomy of an HTML 5 mobile web app Anatomy of an HTML 5 mobile web app
Anatomy of an HTML 5 mobile web app Ivano Malavolta
 
"Native" Apps with APEX and PhoneGap
"Native" Apps with APEX and PhoneGap"Native" Apps with APEX and PhoneGap
"Native" Apps with APEX and PhoneGapChristian Rokitta
 
Google app development
Google app developmentGoogle app development
Google app developmentAurel Medvegy
 
Google app developers
Google app developersGoogle app developers
Google app developersAurel Medvegy
 
Web software development
Web software developmentWeb software development
Web software developmentAurel Medvegy
 
Google app developer
Google app developerGoogle app developer
Google app developerAurel Medvegy
 
Google apps development
Google apps developmentGoogle apps development
Google apps developmentAurel Medvegy
 
Google apps reseller
Google apps resellerGoogle apps reseller
Google apps resellerAurel Medvegy
 
Cloud service provider
Cloud service providerCloud service provider
Cloud service providerAurel Medvegy
 

Similaire à Seattle bestpractices2010 (20)

Developing Windows Phone 8 apps using PhoneGap
Developing Windows Phone 8 apps using PhoneGapDeveloping Windows Phone 8 apps using PhoneGap
Developing Windows Phone 8 apps using PhoneGap
 
Getting started with PhoneGap
Getting started with PhoneGapGetting started with PhoneGap
Getting started with PhoneGap
 
Service worker API
Service worker APIService worker API
Service worker API
 
Anatomy of an HTML 5 mobile web app
Anatomy of an HTML 5 mobile web app Anatomy of an HTML 5 mobile web app
Anatomy of an HTML 5 mobile web app
 
Appengine json
Appengine jsonAppengine json
Appengine json
 
Hybrid mobile apps
Hybrid mobile appsHybrid mobile apps
Hybrid mobile apps
 
"Native" Apps with APEX and PhoneGap
"Native" Apps with APEX and PhoneGap"Native" Apps with APEX and PhoneGap
"Native" Apps with APEX and PhoneGap
 
Google app development
Google app developmentGoogle app development
Google app development
 
Google app developers
Google app developersGoogle app developers
Google app developers
 
Google development
Google developmentGoogle development
Google development
 
Google app
Google appGoogle app
Google app
 
Web software development
Web software developmentWeb software development
Web software development
 
Google app developer
Google app developerGoogle app developer
Google app developer
 
Google web tools
Google web toolsGoogle web tools
Google web tools
 
Google apps development
Google apps developmentGoogle apps development
Google apps development
 
Google app pricing
Google app pricingGoogle app pricing
Google app pricing
 
Create google apps
Create google appsCreate google apps
Create google apps
 
Google apps reseller
Google apps resellerGoogle apps reseller
Google apps reseller
 
Cloud service provider
Cloud service providerCloud service provider
Cloud service provider
 
Google apps
Google appsGoogle apps
Google apps
 

Dernier

Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
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.pdfsudhanshuwaghmare1
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
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 DevelopmentsTrustArc
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
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...apidays
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 

Dernier (20)

Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
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
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
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
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
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...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 

Seattle bestpractices2010

  • 1. PhoneGap Development Best Practices Fil Maj Nitobi Software
  • 2. Overview • Fast cross-platform prototyping, how to do it. • Templating. • Offline strategies. • Persistent storage. • File API. • XUI overview. • When *not* to use PhoneGap.
  • 3. Cross-platform Prototyping with PhoneGap • Main advantage of PhoneGap is you can reuse your web application source code across platforms. • A good, quick approach is to write one set of assets and ‘tweak’ across platforms. • HTML and CSS can be, more-or-less, written once. – Highly recommend writing percentage-based styles initially, and down the road tweaking on a per-platform basis. – Combined with a <meta name=“viewport”> tag (which tells the browser the size of the screen it’s being viewed in), results are good.
  • 4. Cross-platform Prototyping with PhoneGap, cont. • JavaScript is tougher, mainly due to weak BlackBerry support. However, latest XUI works on BlackBerry! More on this in a bit. – A process that has brought a measure of success for us is to first determine which platforms to target, and then build your mobile application logic in a JavaScript framework that works with the ‘lowest common denominator’ platform. JavaScript frameworks are your friends (jQuery, MooTools, XUI, etc.). – Existing software development best practices apply. Use a layered and modular approach for your JavaScript. – MVC (model-view-controller) paradigm is great for prototyping, as you can revisit and, if need be, recode particular modules of your app as you iterate. • Model = PhoneGap JS API + offline storage/cache (+ Lawnchair?) • Controller = JavaScript • View = HTML + CSS
  • 5. Templating • Common web development practice used to encapsulate view components of an app. • As you work on an app, you notice repeatable HTML/CSS patterns that come up. Don’t copy+paste it! – Encapsulate the view pattern HTML aka ‘template’ in a JavaScript string: var tweetTemplate = „<div class=“tweet”>{USER} said {MESSAGE}</div>‟; – Create a JavaScript function that takes the template and replaces the tokens (placeholders) with actual data: function tweetify(data) { var tweets = document.createElement(„div‟); var newHTML = „‟; for (var i =0; i<data.length;i++) { var tweet = tweetTemplate.replace(/{USER}/,data[i].user); tweet = j.replace(/{MESSAGE}/,data[i].message); newHTML += tweet; } tweets.innerHTML += tweet; document.getElementById(„content‟).appendChild(tweets); } • This approach follows the MVC paradigm and is a good example of separation of concerns. Also easy to read, easy to extend and reusable. • John Resig blogged about this, he doesn’t use regex but instead he uses: tweetTemplate.split(“match”).join(“replace”). It’s quicker apparently: http://ejohn.org/blog/javascript-micro-templating/
  • 6. Offline Strategies • Inherently, mobile devices will not be networked all the time. Bad coverage, on the plane, no data plan, etc. • Extremely important for every application to take this into account, especially for iPhone. It is a hard criteria in Apple’s App review process (to see how gracefully an app handles lack of internet connection). • PhoneGap offers reachability API, example: http://github.com/phonegap/mobile- spec/blob/master/tests/network.tests.js
  • 7. Persistent Storage • iPhone has SQLite, Safari implements the HTML 5 spec. Tutorial: http://phonegap.pbworks.com/Adding-SQL- Database-support-to-your-iPhone-App – Note: each page in a PhoneGap app can have only a single database object open, and its maximum store size is 5 megabytes (2 MB on Android, but you can change this to suit your needs). Take this into account when using a single-page approach to a PhoneGap app (more on this later). • BlackBerry has ‘persistent storage’ – a giant key/value store. Code exists to access this, but we haven’t figured out how to fit it into the PhoneGap API. Somehow it needs to align with the other platforms. Ask me (filip.maj@nitobi.com) for it if you want it!
  • 8. File API • You can read/write files from PhoneGap too. Implementations available at our own local repositories (not yet part of the spec / public API). – http://github.com/purplecabbage/phonegap- iphone/blob/master/PhoneGapLib/javascripts/core/file.js – BlackBerry native code is present but needs a JavaScript wrapper. – Android File I/O got revamped recently. – Also: Mobile Spec tests are NOT up to date and platforms are fragmented on the implementation of this feature. It needs some work! • Work is ongoing to line our file API up with the HTML 5 specification: http://www.w3.org/TR/2009/WD-FileAPI- 20091117/#dfn-empty
  • 9. XUI Overview • Another (!) JavaScript framework: xuijs.com • This one’s special, though: specifically designed for mobile devices. • Biggest win: small footprint (~6-10kb). • Inspired by jQuery with a very similar syntax. • Works on iPhone, Android, Symbian, Palm and… drum roll… BlackBerry too! But you need to build it specifically for BlackBerry; the output script files are labelled as core, more or bb – the bb file is for BlackBerry. • Is the recommended framework to use with PhoneGap.
  • 10. PhoneGap Performance Tips • For small apps, use a single HTML page. – Use JavaScript to show/hide page elements based on user interaction instead of linking to a separate page. – Especially important for BlackBerry, since each new page request forces the device to encode requested assets into base64 on-the-fly. • Obfuscate / crunch your JavaScript before release. – Devices only reserve a bit of memory for JavaScript interpreters for the browser. If your JavaScript is small enough, it won’t be necessary for the browser to constantly page your scripts in/out of the browser memory. iPhone, for example, has 25kb of memory reserved for JavaScript parsing.
  • 11. PhoneGap Limitations • As important as knowing how to use PhoneGap is also knowing when NOT to use it. – Complex games, intensive graphics. Use OpenGL for that, not PhoneGap. – For slower phones (not iPhone, not Nexus One, not Xperia X10), PhoneGap apps using the latest interactive Google Maps APIs tend to be slow. Static maps OK, though.