SlideShare a Scribd company logo
1 of 29
Hacks for Native and Mobile Web
Applications
Aaron Pedersen
www.developmentarc.com
www.maqueapp.com
www.pedanco.com
Confession
“Less about PhoneGap and more about mobile and desktop
application development in JavaScript”
The bio
What we build…
• Recent Enterprise-level web applications
• AppNexus (Rails, CoffeeScript, scss)
• Pedanco.com (Rails, CoffeeScript, scss)
• Maqueapp.com (Flex)
• DHAP Digitial (JavaScript, CSS)
• Startup that will remain nameless (JavaScript, PhoneGap, CSS)
Once upon a time…
Client comes to us and asks us to
“Use our web skills to build a native application”
Oh and
“it needs to work on desktop and tablet web with the same
code base”
We say…
No problem!
Using our web skills to build a native application
Well…
A few issues along the way
What were the issues?
• Architecting a web application like an application
• How to structure your application for multiple developers
• How to structure your app to run across multiple platforms
• Mobile specific features
• How to detect platform?
• Detect display resolution?
• Mobile vs. Web
• Sound
• Touch events
• Performance
• Animations were slow!!!!
• Garbage collection
Lessons && Hacks
13 lessons and hacks to help you along the way
#1 Architecture: Structuring Application
• MVC that sh$t or just split up your code!
• Each View is a JavaScript class
• Have Models for each API call
• Write as little HTML in your JavaScript as possible
#1 Architecture: Structuring Application
Require.js – Module Loader
http://requirejs.org/
Backbone.js - Skelton view architecture (Views,
Models/Collections, Events)
http://backbonejs.org/
Handlebars– Javascript/html template engine
http://handlebarsjs.com/
#1 Architecture: Structuring Application
• MVC that sh$t
• Each view is a JavaScript class
• Have models for each API call
• Write as little HTML in your JavaScript as possible
#2 Architecture: Across Multiple Environments
Require.js
• Production vs. Development
• Development: loads each JavaScript file as it’s needed.
• Allows for debugging
• Allows for quicker development
• Production: compiles modules of JavaScript/CSS into single files
• Minification
• Uglify
• http://requirejs.org/docs/optimization.html
• Mobile vs. Web vs. Production vs. Dev
• RequireJS provides pragmas
• Build options to add/remove code based on build settings
#2 Architecture: Across Multiple Environments
#3 Setting up your Project Folder Structure
• Keep your code in a source folder
• Build (via require.js) to a different folders
• Example
• app-source/
• app/
• app-native/
• PhoneGap
• Use PhoneGap Build whenever possible
• When you can’t. Keep your code out of XCode!!!!
• Symlink your www directory to ‘app-native’
#4 Detecting Your Environment
• Phonegap
• device.name
• http://docs.phonegap.com/en/2.7.0/cordova_device_device.md.html#Device
• Web/Mobile web…Get a script!
• https://gist.github.com/lerivin/4393058
• Provides
• Browser
• OS
• isMobile
• isTouch
• isNative
• Viewport (width/height)
• Resolution
• isHighResolution (see next tip)
#5 Detecting Your Resolution
#6 Slow Animations: CSS Transitions
• Don’t use JavaScript animations
• Use CSS where possible
• JQuery Enhanced Animations
• https://github.com/benbarnett/jQuery-Animate-Enhanced
• Converts normal jQuery animations into CSS equivalents
• left : using translate(x, y) or translate3d(x, y, z)
• top : using translate(x, y) or translate3d(x, y, z)
• right
• bottom
• opacity
• width
• height
#7 Slow Animations: Let Hardware do the Work
#8 Garbage Collection: Images
• If you add and remove lots of images. Clean them up!
• Before removing
• Clear src tag
• Clear background-image
• *Some people say to destroy the src attribute.
• *Others say to replace the src, with a spacer gif.
#8 Garbage Collection: Images
#9 Garbage Collection: HTML
• Clean up your HTML or you will pay!
• Don’t just replace html()
• Know the difference from detach() and remove()
• detach() removes element from DOM
• Useful when you are going to reuse elements
• remove() removed element from DOM, along with all data and events
• Use when discarding elements for good
#9 Garbage Collection: HTML
#10 Click vs. Touch
• Click is slow on mobile
• 300+ millisecond delay
• Backbone
• Override Backbone’s delegateEvent function
• If mobile, replace ‘click’ with ‘touchstart’
• Use a plugin
• https://github.com/nervetattoo/backbone.touch
#11 Where are the gestures?
• Where’s my swipes!
• Mobile only has
• touchstart
• touchend
• JQuery Mobile has the gestures
• swipe, swipeLeft, swipeRight, tap, etc…
• Get events with no components by using a custom build
• Clone via https://github.com/jquery/jquery-mobile
• Follow build instructions
• https://github.com/jquery/jquery-
mobile/blob/master/README.md
• Use Builder
• http://jquerymobile.com/download-builder/
#12 Sound
• HTML 5 sound
• HTML 5 sound is like video, lots of formats
• We used
• http://buzz.jaysalvat.com/
• Lesson learned, audio can’t auto-play!
• Must have user interaction
• And you can’t fake it with a jQuery click
• Phonegap: Use native sound API
• Can auto-play!
#13 Use the Future
• JQuery 2.0
• Lighter, faster, better
• No more IE 6/7/8 support (perfect for mobile!)
• Custom builds (use native selectors vs. sizzle)
• https://github.com/jquery/jquery/#readme
• http://projects.jga.me/jquery-builder/
• Still using JavaScript animations
Or
• Zepto
• Go fast and lean!
• Interchangeable with JQuery API (Backbone can use it)
• Warning: Might not work with jQuery plugins
#14 PhoneGap Build
• Use Phonegap Build whenever you can.
• Phone Gap Build – https://build.phonegap.com/
• Build Config - http://aj-software.com/configap/
• Does not require you to build XCode (iOS) project
• Does not require you to build Android development environment
• Does not require you to build BlackBerry environment
• But….
• Make sure you test on the device as you develop!
• Make the app work as a web application in your devices browser so you can
test
• Ignore what I said above and create XCode, Android, BlackBerry , etc…
environment and run their simulators and/or deploy to your device.
• ALWAYS Test on your device!
Thank you
• If you like food and like to complain, tell them about
Aaron Pedersen
• @aaronpedersen
• aaron@developmentarc.com
• developmentarc.com
• pedanco.com
• maqueapp.com

More Related Content

What's hot

Beginning jQuery Mobile
Beginning jQuery MobileBeginning jQuery Mobile
Beginning jQuery MobileTroy Miles
 
Building a Desktop Streaming console with Electron and ReactJS
Building a Desktop Streaming console with Electron and ReactJSBuilding a Desktop Streaming console with Electron and ReactJS
Building a Desktop Streaming console with Electron and ReactJSEmanuele Rampichini
 
WebVR with Babylon.JS
WebVR with Babylon.JSWebVR with Babylon.JS
WebVR with Babylon.JSTimmy Kokke
 
SlickGrid Touch: Making complex JavaScript widgets work on mobile devices
SlickGrid Touch: Making complex JavaScript widgets work on mobile devicesSlickGrid Touch: Making complex JavaScript widgets work on mobile devices
SlickGrid Touch: Making complex JavaScript widgets work on mobile devicesreebalazs
 
PhoneGap in a Day
PhoneGap in a DayPhoneGap in a Day
PhoneGap in a DayTroy Miles
 
Thinking in Components
Thinking in ComponentsThinking in Components
Thinking in ComponentsFITC
 
Automated perf optimization - jQuery Conference
Automated perf optimization - jQuery ConferenceAutomated perf optimization - jQuery Conference
Automated perf optimization - jQuery ConferenceMatthew Lancaster
 
Electron - Build cross platform desktop apps
Electron - Build cross platform desktop appsElectron - Build cross platform desktop apps
Electron - Build cross platform desktop appsPriyaranjan Mohanty
 
Rise of the hybrids
Rise of the hybridsRise of the hybrids
Rise of the hybridsOron Ben Zvi
 
Creating an hybrid app in minutes with Ionic Framework
Creating an hybrid app in minutes with Ionic FrameworkCreating an hybrid app in minutes with Ionic Framework
Creating an hybrid app in minutes with Ionic FrameworkJulien Renaux
 
Desktop Apps in a Javascript World - Electron
Desktop Apps in a Javascript World - ElectronDesktop Apps in a Javascript World - Electron
Desktop Apps in a Javascript World - ElectronMarc MacLeod
 
HTML5 Web Workers-unleashed
HTML5 Web Workers-unleashedHTML5 Web Workers-unleashed
HTML5 Web Workers-unleashedPeter Lubbers
 
Why front-end matters in 2019
Why front-end matters in 2019Why front-end matters in 2019
Why front-end matters in 2019Timmy Kokke
 
Untangling - fall2017 - week5
Untangling - fall2017 - week5Untangling - fall2017 - week5
Untangling - fall2017 - week5Derek Jacoby
 
Transforming Front-End Disaster Code™ Into A Maintainable Masterpiece
Transforming Front-End Disaster Code™ Into A Maintainable MasterpieceTransforming Front-End Disaster Code™ Into A Maintainable Masterpiece
Transforming Front-End Disaster Code™ Into A Maintainable MasterpieceDan Gribbin
 
Phonegap Day 2016: Ember/JS & Hybrid Apps Tips
Phonegap Day 2016: Ember/JS & Hybrid Apps TipsPhonegap Day 2016: Ember/JS & Hybrid Apps Tips
Phonegap Day 2016: Ember/JS & Hybrid Apps TipsAlex Blom
 
Native Desktop App with Node.js Webkit (HTML, CSS & Javascript)
Native Desktop App with Node.js Webkit (HTML, CSS & Javascript)Native Desktop App with Node.js Webkit (HTML, CSS & Javascript)
Native Desktop App with Node.js Webkit (HTML, CSS & Javascript)Eddie Lau
 
Creating mobile apps - an introduction to Ionic (Engage 2016)
Creating mobile apps - an introduction to Ionic (Engage 2016)Creating mobile apps - an introduction to Ionic (Engage 2016)
Creating mobile apps - an introduction to Ionic (Engage 2016)Mark Leusink
 
Wulin kungfu final
Wulin kungfu finalWulin kungfu final
Wulin kungfu finalJimmy Huang
 

What's hot (20)

Beginning jQuery Mobile
Beginning jQuery MobileBeginning jQuery Mobile
Beginning jQuery Mobile
 
Building a Desktop Streaming console with Electron and ReactJS
Building a Desktop Streaming console with Electron and ReactJSBuilding a Desktop Streaming console with Electron and ReactJS
Building a Desktop Streaming console with Electron and ReactJS
 
WebVR with Babylon.JS
WebVR with Babylon.JSWebVR with Babylon.JS
WebVR with Babylon.JS
 
SlickGrid Touch: Making complex JavaScript widgets work on mobile devices
SlickGrid Touch: Making complex JavaScript widgets work on mobile devicesSlickGrid Touch: Making complex JavaScript widgets work on mobile devices
SlickGrid Touch: Making complex JavaScript widgets work on mobile devices
 
Ionic Framework
Ionic FrameworkIonic Framework
Ionic Framework
 
PhoneGap in a Day
PhoneGap in a DayPhoneGap in a Day
PhoneGap in a Day
 
Thinking in Components
Thinking in ComponentsThinking in Components
Thinking in Components
 
Automated perf optimization - jQuery Conference
Automated perf optimization - jQuery ConferenceAutomated perf optimization - jQuery Conference
Automated perf optimization - jQuery Conference
 
Electron - Build cross platform desktop apps
Electron - Build cross platform desktop appsElectron - Build cross platform desktop apps
Electron - Build cross platform desktop apps
 
Rise of the hybrids
Rise of the hybridsRise of the hybrids
Rise of the hybrids
 
Creating an hybrid app in minutes with Ionic Framework
Creating an hybrid app in minutes with Ionic FrameworkCreating an hybrid app in minutes with Ionic Framework
Creating an hybrid app in minutes with Ionic Framework
 
Desktop Apps in a Javascript World - Electron
Desktop Apps in a Javascript World - ElectronDesktop Apps in a Javascript World - Electron
Desktop Apps in a Javascript World - Electron
 
HTML5 Web Workers-unleashed
HTML5 Web Workers-unleashedHTML5 Web Workers-unleashed
HTML5 Web Workers-unleashed
 
Why front-end matters in 2019
Why front-end matters in 2019Why front-end matters in 2019
Why front-end matters in 2019
 
Untangling - fall2017 - week5
Untangling - fall2017 - week5Untangling - fall2017 - week5
Untangling - fall2017 - week5
 
Transforming Front-End Disaster Code™ Into A Maintainable Masterpiece
Transforming Front-End Disaster Code™ Into A Maintainable MasterpieceTransforming Front-End Disaster Code™ Into A Maintainable Masterpiece
Transforming Front-End Disaster Code™ Into A Maintainable Masterpiece
 
Phonegap Day 2016: Ember/JS & Hybrid Apps Tips
Phonegap Day 2016: Ember/JS & Hybrid Apps TipsPhonegap Day 2016: Ember/JS & Hybrid Apps Tips
Phonegap Day 2016: Ember/JS & Hybrid Apps Tips
 
Native Desktop App with Node.js Webkit (HTML, CSS & Javascript)
Native Desktop App with Node.js Webkit (HTML, CSS & Javascript)Native Desktop App with Node.js Webkit (HTML, CSS & Javascript)
Native Desktop App with Node.js Webkit (HTML, CSS & Javascript)
 
Creating mobile apps - an introduction to Ionic (Engage 2016)
Creating mobile apps - an introduction to Ionic (Engage 2016)Creating mobile apps - an introduction to Ionic (Engage 2016)
Creating mobile apps - an introduction to Ionic (Engage 2016)
 
Wulin kungfu final
Wulin kungfu finalWulin kungfu final
Wulin kungfu final
 

Viewers also liked

2014 01-20 economic-strategy_telecom_operators_mw_ru
2014 01-20 economic-strategy_telecom_operators_mw_ru2014 01-20 economic-strategy_telecom_operators_mw_ru
2014 01-20 economic-strategy_telecom_operators_mw_ruJ'son and Partners Consulting
 
Love and logics powerpoint
Love and logics powerpointLove and logics powerpoint
Love and logics powerpointloveandlogics
 
Groupon final presentation
Groupon final presentationGroupon final presentation
Groupon final presentationahagers
 
Verbs pinkmoonpio[1]
Verbs pinkmoonpio[1]Verbs pinkmoonpio[1]
Verbs pinkmoonpio[1]xapizloca
 
Adobe Flex Don't Style It, Skin it!
Adobe Flex Don't Style It, Skin it!Adobe Flex Don't Style It, Skin it!
Adobe Flex Don't Style It, Skin it!DevelopmentArc LLC
 

Viewers also liked (7)

2014 01-20 economic-strategy_telecom_operators_mw_ru
2014 01-20 economic-strategy_telecom_operators_mw_ru2014 01-20 economic-strategy_telecom_operators_mw_ru
2014 01-20 economic-strategy_telecom_operators_mw_ru
 
Love and logics powerpoint
Love and logics powerpointLove and logics powerpoint
Love and logics powerpoint
 
Groupon final presentation
Groupon final presentationGroupon final presentation
Groupon final presentation
 
Words
WordsWords
Words
 
Verbs pinkmoonpio[1]
Verbs pinkmoonpio[1]Verbs pinkmoonpio[1]
Verbs pinkmoonpio[1]
 
Sc mind map year 5
Sc mind map year 5Sc mind map year 5
Sc mind map year 5
 
Adobe Flex Don't Style It, Skin it!
Adobe Flex Don't Style It, Skin it!Adobe Flex Don't Style It, Skin it!
Adobe Flex Don't Style It, Skin it!
 

Similar to Mobile native-hacks

Appcelerator Titanium Intro
Appcelerator Titanium IntroAppcelerator Titanium Intro
Appcelerator Titanium IntroNicholas Jansma
 
Mobile ECM with JavaScript - JSE 2011
Mobile ECM with JavaScript - JSE 2011Mobile ECM with JavaScript - JSE 2011
Mobile ECM with JavaScript - JSE 2011Nuxeo
 
Phonegap for Engineers
Phonegap for EngineersPhonegap for Engineers
Phonegap for EngineersBrian LeRoux
 
The Mobile Development Landscape
The Mobile Development LandscapeThe Mobile Development Landscape
The Mobile Development LandscapeAmbert Ho
 
Phonegap - An Introduction
Phonegap - An IntroductionPhonegap - An Introduction
Phonegap - An IntroductionTyler Johnston
 
HTML5 is the Future of Mobile, PhoneGap Takes You There Today
HTML5 is the Future of Mobile, PhoneGap Takes You There TodayHTML5 is the Future of Mobile, PhoneGap Takes You There Today
HTML5 is the Future of Mobile, PhoneGap Takes You There Todaydavyjones
 
«I knew there had to be a better way to build mobile app»​
«I knew there had to be a better way to build mobile app»​«I knew there had to be a better way to build mobile app»​
«I knew there had to be a better way to build mobile app»​FDConf
 
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
 
移动端Web app开发
移动端Web app开发移动端Web app开发
移动端Web app开发Zhang Xiaoxue
 
Google App Engine Java, Groovy and Gaelyk
Google App Engine Java, Groovy and GaelykGoogle App Engine Java, Groovy and Gaelyk
Google App Engine Java, Groovy and GaelykGuillaume Laforge
 
I knew there had to be a better way to build mobile apps
I knew there had to be a better way to build mobile appsI knew there had to be a better way to build mobile apps
I knew there had to be a better way to build mobile appsAlius Petraška
 
So you want to build a mobile app - HTML5 vs. Native @ the Boston Mobile Expe...
So you want to build a mobile app - HTML5 vs. Native @ the Boston Mobile Expe...So you want to build a mobile app - HTML5 vs. Native @ the Boston Mobile Expe...
So you want to build a mobile app - HTML5 vs. Native @ the Boston Mobile Expe...Yottaa
 
Cross Platform Mobile Development
Cross Platform Mobile DevelopmentCross Platform Mobile Development
Cross Platform Mobile DevelopmentManesh Lad
 
The Mobile Web Revealed For The Java Developer
The Mobile Web Revealed For The Java DeveloperThe Mobile Web Revealed For The Java Developer
The Mobile Web Revealed For The Java Developerbalunasj
 
Mobile App Development
Mobile App DevelopmentMobile App Development
Mobile App DevelopmentChris Morrell
 
Hybrid Mobile Development with Apache Cordova and
Hybrid Mobile Development with Apache Cordova and Hybrid Mobile Development with Apache Cordova and
Hybrid Mobile Development with Apache Cordova and Ryan Cuprak
 
React Native - DILo Surabaya
React Native -  DILo SurabayaReact Native -  DILo Surabaya
React Native - DILo SurabayaDILo Surabaya
 

Similar to Mobile native-hacks (20)

Txjs
TxjsTxjs
Txjs
 
Appcelerator Titanium Intro
Appcelerator Titanium IntroAppcelerator Titanium Intro
Appcelerator Titanium Intro
 
Mobile ECM with JavaScript - JSE 2011
Mobile ECM with JavaScript - JSE 2011Mobile ECM with JavaScript - JSE 2011
Mobile ECM with JavaScript - JSE 2011
 
Phonegap for Engineers
Phonegap for EngineersPhonegap for Engineers
Phonegap for Engineers
 
The Mobile Development Landscape
The Mobile Development LandscapeThe Mobile Development Landscape
The Mobile Development Landscape
 
Phonegap - An Introduction
Phonegap - An IntroductionPhonegap - An Introduction
Phonegap - An Introduction
 
HTML5 is the Future of Mobile, PhoneGap Takes You There Today
HTML5 is the Future of Mobile, PhoneGap Takes You There TodayHTML5 is the Future of Mobile, PhoneGap Takes You There Today
HTML5 is the Future of Mobile, PhoneGap Takes You There Today
 
Future of Mobile
Future of MobileFuture of Mobile
Future of Mobile
 
«I knew there had to be a better way to build mobile app»​
«I knew there had to be a better way to build mobile app»​«I knew there had to be a better way to build mobile app»​
«I knew there had to be a better way to build mobile app»​
 
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
 
移动端Web app开发
移动端Web app开发移动端Web app开发
移动端Web app开发
 
Google App Engine Java, Groovy and Gaelyk
Google App Engine Java, Groovy and GaelykGoogle App Engine Java, Groovy and Gaelyk
Google App Engine Java, Groovy and Gaelyk
 
I knew there had to be a better way to build mobile apps
I knew there had to be a better way to build mobile appsI knew there had to be a better way to build mobile apps
I knew there had to be a better way to build mobile apps
 
So you want to build a mobile app - HTML5 vs. Native @ the Boston Mobile Expe...
So you want to build a mobile app - HTML5 vs. Native @ the Boston Mobile Expe...So you want to build a mobile app - HTML5 vs. Native @ the Boston Mobile Expe...
So you want to build a mobile app - HTML5 vs. Native @ the Boston Mobile Expe...
 
Cross Platform Mobile Development
Cross Platform Mobile DevelopmentCross Platform Mobile Development
Cross Platform Mobile Development
 
The Mobile Web Revealed For The Java Developer
The Mobile Web Revealed For The Java DeveloperThe Mobile Web Revealed For The Java Developer
The Mobile Web Revealed For The Java Developer
 
Mobile App Development
Mobile App DevelopmentMobile App Development
Mobile App Development
 
Hybrid Mobile Development with Apache Cordova and
Hybrid Mobile Development with Apache Cordova and Hybrid Mobile Development with Apache Cordova and
Hybrid Mobile Development with Apache Cordova and
 
Cross-Platform Development
Cross-Platform DevelopmentCross-Platform Development
Cross-Platform Development
 
React Native - DILo Surabaya
React Native -  DILo SurabayaReact Native -  DILo Surabaya
React Native - DILo Surabaya
 

Mobile native-hacks

  • 1. Hacks for Native and Mobile Web Applications Aaron Pedersen www.developmentarc.com www.maqueapp.com www.pedanco.com
  • 2. Confession “Less about PhoneGap and more about mobile and desktop application development in JavaScript”
  • 4. What we build… • Recent Enterprise-level web applications • AppNexus (Rails, CoffeeScript, scss) • Pedanco.com (Rails, CoffeeScript, scss) • Maqueapp.com (Flex) • DHAP Digitial (JavaScript, CSS) • Startup that will remain nameless (JavaScript, PhoneGap, CSS)
  • 5. Once upon a time… Client comes to us and asks us to “Use our web skills to build a native application” Oh and “it needs to work on desktop and tablet web with the same code base” We say…
  • 6. No problem! Using our web skills to build a native application
  • 8. A few issues along the way What were the issues? • Architecting a web application like an application • How to structure your application for multiple developers • How to structure your app to run across multiple platforms • Mobile specific features • How to detect platform? • Detect display resolution? • Mobile vs. Web • Sound • Touch events • Performance • Animations were slow!!!! • Garbage collection
  • 9. Lessons && Hacks 13 lessons and hacks to help you along the way
  • 10. #1 Architecture: Structuring Application • MVC that sh$t or just split up your code! • Each View is a JavaScript class • Have Models for each API call • Write as little HTML in your JavaScript as possible
  • 11. #1 Architecture: Structuring Application Require.js – Module Loader http://requirejs.org/ Backbone.js - Skelton view architecture (Views, Models/Collections, Events) http://backbonejs.org/ Handlebars– Javascript/html template engine http://handlebarsjs.com/
  • 12. #1 Architecture: Structuring Application • MVC that sh$t • Each view is a JavaScript class • Have models for each API call • Write as little HTML in your JavaScript as possible
  • 13. #2 Architecture: Across Multiple Environments Require.js • Production vs. Development • Development: loads each JavaScript file as it’s needed. • Allows for debugging • Allows for quicker development • Production: compiles modules of JavaScript/CSS into single files • Minification • Uglify • http://requirejs.org/docs/optimization.html • Mobile vs. Web vs. Production vs. Dev • RequireJS provides pragmas • Build options to add/remove code based on build settings
  • 14. #2 Architecture: Across Multiple Environments
  • 15. #3 Setting up your Project Folder Structure • Keep your code in a source folder • Build (via require.js) to a different folders • Example • app-source/ • app/ • app-native/ • PhoneGap • Use PhoneGap Build whenever possible • When you can’t. Keep your code out of XCode!!!! • Symlink your www directory to ‘app-native’
  • 16. #4 Detecting Your Environment • Phonegap • device.name • http://docs.phonegap.com/en/2.7.0/cordova_device_device.md.html#Device • Web/Mobile web…Get a script! • https://gist.github.com/lerivin/4393058 • Provides • Browser • OS • isMobile • isTouch • isNative • Viewport (width/height) • Resolution • isHighResolution (see next tip)
  • 17. #5 Detecting Your Resolution
  • 18. #6 Slow Animations: CSS Transitions • Don’t use JavaScript animations • Use CSS where possible • JQuery Enhanced Animations • https://github.com/benbarnett/jQuery-Animate-Enhanced • Converts normal jQuery animations into CSS equivalents • left : using translate(x, y) or translate3d(x, y, z) • top : using translate(x, y) or translate3d(x, y, z) • right • bottom • opacity • width • height
  • 19. #7 Slow Animations: Let Hardware do the Work
  • 20. #8 Garbage Collection: Images • If you add and remove lots of images. Clean them up! • Before removing • Clear src tag • Clear background-image • *Some people say to destroy the src attribute. • *Others say to replace the src, with a spacer gif.
  • 22. #9 Garbage Collection: HTML • Clean up your HTML or you will pay! • Don’t just replace html() • Know the difference from detach() and remove() • detach() removes element from DOM • Useful when you are going to reuse elements • remove() removed element from DOM, along with all data and events • Use when discarding elements for good
  • 24. #10 Click vs. Touch • Click is slow on mobile • 300+ millisecond delay • Backbone • Override Backbone’s delegateEvent function • If mobile, replace ‘click’ with ‘touchstart’ • Use a plugin • https://github.com/nervetattoo/backbone.touch
  • 25. #11 Where are the gestures? • Where’s my swipes! • Mobile only has • touchstart • touchend • JQuery Mobile has the gestures • swipe, swipeLeft, swipeRight, tap, etc… • Get events with no components by using a custom build • Clone via https://github.com/jquery/jquery-mobile • Follow build instructions • https://github.com/jquery/jquery- mobile/blob/master/README.md • Use Builder • http://jquerymobile.com/download-builder/
  • 26. #12 Sound • HTML 5 sound • HTML 5 sound is like video, lots of formats • We used • http://buzz.jaysalvat.com/ • Lesson learned, audio can’t auto-play! • Must have user interaction • And you can’t fake it with a jQuery click • Phonegap: Use native sound API • Can auto-play!
  • 27. #13 Use the Future • JQuery 2.0 • Lighter, faster, better • No more IE 6/7/8 support (perfect for mobile!) • Custom builds (use native selectors vs. sizzle) • https://github.com/jquery/jquery/#readme • http://projects.jga.me/jquery-builder/ • Still using JavaScript animations Or • Zepto • Go fast and lean! • Interchangeable with JQuery API (Backbone can use it) • Warning: Might not work with jQuery plugins
  • 28. #14 PhoneGap Build • Use Phonegap Build whenever you can. • Phone Gap Build – https://build.phonegap.com/ • Build Config - http://aj-software.com/configap/ • Does not require you to build XCode (iOS) project • Does not require you to build Android development environment • Does not require you to build BlackBerry environment • But…. • Make sure you test on the device as you develop! • Make the app work as a web application in your devices browser so you can test • Ignore what I said above and create XCode, Android, BlackBerry , etc… environment and run their simulators and/or deploy to your device. • ALWAYS Test on your device!
  • 29. Thank you • If you like food and like to complain, tell them about Aaron Pedersen • @aaronpedersen • aaron@developmentarc.com • developmentarc.com • pedanco.com • maqueapp.com