SlideShare a Scribd company logo
Introduction to Mobile Web
     and Best Practices
        Bryan Hughes, Ph.D.
         Software Engineer
            Appcelerator

      bhughes@appcelerator.com

                                 1
About Me

           • Appcelerator Software Engineer in
             the JavaScript Engineering group

           • Previously developed the HTML 5
             platform at Particle Code

           • Ph.D. in Electrical Engineering and
             Computer Science from Texas
             Tech University




                                             2
Mobile Web
Platform Overview
Titanium Mobile Target

                  • Provides similar experience to
                    Android and iOS

                  • Not intended for integration into
                    existing web apps/frameworks

                  • Designed specifically for mobile
                    browsers and devices




                                                        4
Single Page Web App

                 • Apps are hosted on traditional web
                   servers

                 • Users use their device‟ browser to
                   navigate to the URL of the app

                 • Apps are a single page only




                                                   5
Architecture

               • Uses HTML 5 technologies to
                 implement the Titanium Mobile API

               • APIs implemented using
                 Asynchronous Module Definition

               • Everything is require()‟d


                  var ad = require('Ti/UI/AlertDialog'),
                    foo = new ad({
                        title: 'Mobile Web Rules!'
                    });
                  foo.show();



                                                           6
User Interface




• Controls are
  composites of
  other controls

• Custom layout    Ti.UI.View
  algorithm
                   Ti.UI.View
                   Ti.UI.ImageView
                   Ti.UI.Label

                                     7
File System



• Pluggable
  provider
  architecture

• Fully support
  directories,
  binary files, etc.




                       8
Miscellany


         Titanium API                   HTML/CSS API


 Ti.Network.HTTPClient   XML HTTP Request (XHR)


 Ti.Accelerometer        devicemotion window event

                         navigator.geolocation and deviceorientation
 Ti.Geolocation
                         window event

 Touch Gestures          touchstart/move/end window events


 Ti.Media.VideoPlayer    <video> HTML tag


                                                                       9
Mobile Web
Specific Features
Tiapp.xml Options
                <analytics>
                      <use-xhr>true, false</use-xhr>
                </analytics>
                <filesystem>
                      <backend>Ti/_/Filesystem/Local</backend>
                      <registry>preload</registry>
                </filesystem>
                <Instrumentation>true, false</Instrumentation>
                <precache>
                      <image>image path</image>
                      <include>file path</include>
                      <require>module id</require>
                      <locale>locale code</locale>
                </precache>
                <splash>
                      <enabled>true, false</enabled>
                      <inline-css-images>true, false</inline-css-
                </splash>
                <theme>theme name (default is „default‟)</theme>

                                                                    11
Splash Screen




  Created with
  HTML+CSS




                 12
Icons




• Favicon

• Apple Web
  Applications




                 13
Modules

          • CommonJS
            – Can only use Titanium APIs

            – Compatible with Android and iOS

          • MobileWeb
            – Can use any browser features

            – Will not work on Android and iOS




                                                 14
Hybrid Apps




  100% Written
   in Titanium




                 15
Debugging




 Debug like any
 other web page




                  16
Instrumentation




• Layout

• Networking

• System Load
  Time




                  17
Deploying

                            production minifies code

                   function myFunction(parameterOne, parameterTwo) {
• Web server         var parameterOnePlusFive = parameterOne + 5;
  agnostic           var parameterTwoPlusTen = parameterTwo + 10;
                   }
                   myFunction(5 + 10, 15 - 20);
• Deployment:
  development or
  production

                   function myFunction(a,b){var x=a+5,d=b+10}myFunction(15,-5)




                                                                            18
Limitations and
Common Pitfalls
Local Storage



• Several APIs use
  Local Storage

• 5mb Local
  Storage per
  domain

• Exception thrown
  when exceeded




                     20
Cross Domain HTTP


                    if (Ti.Platform.osname === 'mobileweb') {
                      Ti.Network.httpURLFormatter = function (url) {

• Access-Control-           // Create prefix from server’s hostname
                            var newPrefix =
  Allow-Origin                location.protocol + '//' + location.host +
  HTTP header                 (location.port ? ':' + location.port : '');

                            // Make sure URL isn't relative
• Proxy + URL               if (url.indexOf(newPrefix) === -1 &&
                                url.indexOf('://') !== -1) {
  formatter                   url = newPrefix + '/proxy?url=' + url;
                              console.debug('proxying to ' + url);
                            }
                            return url;
                        }
                    }




                                                                            21
WebViews



• Cross domain
  WebViews are
  limited

• Sites with X-
  Frame-Options
  set will not load




                      22
Code Limitations



• Variables and
  functions cannot
  use DOM names

• Titanium objects
  contain many
  “hidden” fields




                     23
Code Minification

                      function myFunction(parameterOne, parameterTwo) {
                        var parameterOnePlusFive = parameterOne + 5;
                        var parameterTwoPlusTen = parameterTwo + 10;
                      }
• Code minification   myFunction(5 + 10, 15 - 20);

  is not code
  obfuscation

• Code/resources      function myFunction(a,b){var x=a+5,d=b+10}myFunction(15,-5)

  cannot be
  secured in
  Mobile Web
                      function myFunction(a, b) {
                        var c = a + 5,
                          d = b + 10;
                      }
                      myFunction(15, -5);

                                                                               24
UI Performance

                 • Two layout passes per layout

                 • Browsers are slower than native

                 • Titanium apps that perform well in
                   Android/iOS may not perform well
                   in Mobile Web




                                                   25
Miscellany

             • Unsupported APIs
                – Database

                – Contacts

                – AudioPlayer

                – Sockets

             • Facebook Site URL must be set

             • Everything must be loaded over
               the network!

                                                26
Browser Compatibility

                  • Recommended
                     – Mobile Safari 4.2+
                     – Android 2.2+
                     – Chrome for Android
                     – Firefox Mobile for Android
                     – BlackBerry 7+, Playbook

                  • Limited Support
                     – Windows Phone 7.5 (Mango)
                     – BlackBerry 6 (Bold)
                                                    27
Optimizing for
Mobile Web
Security



• Everything in the
  app is public
  information

• Don‟t trust the
  client application

• Don‟t put private
  keys in code




                       29
Layout Optimizations

                  • Reduce the number of controls on
                    screen

                  • Only use vertical and horizontal
                    layouts if they are actually needed

                  • Use basic views whenever
                    possible

                  • Use gradients and solid colors
                    instead of images


                                                     30
Image Optimizations



• Compress            JPEG: 371 KB
  images with the
  correct CODEC       PNG: 2.3 MB

• Reduce image
  dimensions

• Reduce color        JPEG: 10.14 KB
  depth
                      PNG: 10.08 KB


                                       31
Pre-caching

              • Cache commonly used source
                code, images, and text files

              • Images are encoded as data URIs

              • Cached resources are inlined in
                index.html




                                                  32
Bryan Hughes, Ph.D.

bhughes@appcelerator.com

                           33

More Related Content

PPT
Top 10 HTML5 Features for Oracle Cloud Developers
PPT
Deep Dive: Oracle WebCenter Content Tips and Traps!
PPTX
1 app 2 developers 3 servers
PPTX
Peter lubbers-html5-offline-web-apps
PDF
Building a Next Generation Mobile Browser using Web technologies
PDF
Web services on IBM i with PHP and Zend Framework
PDF
Web Performance First Aid
PDF
Browser tools that make web development easier
Top 10 HTML5 Features for Oracle Cloud Developers
Deep Dive: Oracle WebCenter Content Tips and Traps!
1 app 2 developers 3 servers
Peter lubbers-html5-offline-web-apps
Building a Next Generation Mobile Browser using Web technologies
Web services on IBM i with PHP and Zend Framework
Web Performance First Aid
Browser tools that make web development easier

What's hot (20)

PPTX
Html5 features: location, history and offline apps
PDF
Architecture of the Web browser
PDF
Best Practices in PHP Application Deployment
PDF
Create a welcoming development environment on IBM i
PPT
Introduction to Alfresco Surf Platform
PDF
A Bit of REST
PDF
Optimizing HTML5 Sites with CQ5/WEM
PPTX
php[world] Magento101
KEY
Introduction to eXo ECM Suite
PPTX
Social Connections 12 - IBM Connections Adminblast
PDF
Deview 2013 mobile browser internals and trends_20131022
PDF
AD109 - Using the IBM Sametime Proxy SDK: WebSphere Portal, IBM Connections -...
PDF
IBM i: Fertile Ground for PHP Developers
PDF
From Zero to ZF: Your first zend framework project on ibm i
PDF
Sencha touchonbb10 bootcamp
PPTX
Code Generation in Magento 2
PDF
HTML5 Offline Web Applications (Silicon Valley User Group)
PDF
Keep Your Code Organized! WordCamp Montreal 2013 Presentation slides
PPTX
Creating Web Templates for SharePoint 2010
PDF
Webアプリケーションフレームワークを利用した効率的なカスタムWeb開発
Html5 features: location, history and offline apps
Architecture of the Web browser
Best Practices in PHP Application Deployment
Create a welcoming development environment on IBM i
Introduction to Alfresco Surf Platform
A Bit of REST
Optimizing HTML5 Sites with CQ5/WEM
php[world] Magento101
Introduction to eXo ECM Suite
Social Connections 12 - IBM Connections Adminblast
Deview 2013 mobile browser internals and trends_20131022
AD109 - Using the IBM Sametime Proxy SDK: WebSphere Portal, IBM Connections -...
IBM i: Fertile Ground for PHP Developers
From Zero to ZF: Your first zend framework project on ibm i
Sencha touchonbb10 bootcamp
Code Generation in Magento 2
HTML5 Offline Web Applications (Silicon Valley User Group)
Keep Your Code Organized! WordCamp Montreal 2013 Presentation slides
Creating Web Templates for SharePoint 2010
Webアプリケーションフレームワークを利用した効率的なカスタムWeb開発
Ad

Similar to Codestrong 2012 breakout session introduction to mobile web and best practices (20)

PDF
Mobile web or native app
PPTX
Top Ten Tips for HTML5/Mobile Web Development
PDF
Cross platform mobile web apps
PDF
Building Cross Platform Mobile Web Apps
PDF
The Enterprise Dilemma: Native vs. Web
PDF
Mobile App Development
PDF
PhoneGap Day - IBM, PhoneGap and the Enterprise
PDF
HTML5 and the dawn of rich mobile web applications pt 1
PDF
HTML5 and the dawn of rich mobile web applications
PDF
A Snapshot of the Mobile HTML5 Revolution
PDF
Building cross platform mobile web apps
PDF
Ideas for addictive series 40 web apps
PPTX
Cross platform-mobile-applications
PPTX
MobiWebApp 2012 - Gaps between standard & tool for native and web mobile appl...
PDF
Hybrid mobile apps
KEY
Library Mobile Web Design: Tips, Tricks and Resources
PDF
Anatomy of an HTML 5 mobile web app
PDF
Building Cloud-Based Cross-Platform Mobile Web Apps
KEY
Open Source World : Using Web Technologies to build native iPhone and Android...
ZIP
Using Web Technologies to Build Native iPhone & Android Applications
Mobile web or native app
Top Ten Tips for HTML5/Mobile Web Development
Cross platform mobile web apps
Building Cross Platform Mobile Web Apps
The Enterprise Dilemma: Native vs. Web
Mobile App Development
PhoneGap Day - IBM, PhoneGap and the Enterprise
HTML5 and the dawn of rich mobile web applications pt 1
HTML5 and the dawn of rich mobile web applications
A Snapshot of the Mobile HTML5 Revolution
Building cross platform mobile web apps
Ideas for addictive series 40 web apps
Cross platform-mobile-applications
MobiWebApp 2012 - Gaps between standard & tool for native and web mobile appl...
Hybrid mobile apps
Library Mobile Web Design: Tips, Tricks and Resources
Anatomy of an HTML 5 mobile web app
Building Cloud-Based Cross-Platform Mobile Web Apps
Open Source World : Using Web Technologies to build native iPhone and Android...
Using Web Technologies to Build Native iPhone & Android Applications
Ad

More from Axway Appcelerator (20)

PDF
Axway Appcelerator - Titanium SDK 6.1.0 - Status, Releases & Roadmap
PPTX
2014 Dublin Web Summit by Jeff Haynie
PPTX
Making the Mobile Mind Shift
PPTX
Stop Debating, Start Measuring
PPTX
Mobile & The New Experience Economy (And What it Means for IT)
PPTX
Apps, APIs & Analytics: What "Mobile First" Really Means
PPTX
Appcelerator Presentation Template
PPTX
Codestrong 2012 keynote jonathan rende, appcelerator's vp of products
PPTX
Codestrong 2012 keynote jeff haynie, appcelerator's ceo
PPTX
Codestrong 2012 keynote how to build a top ten app
PPTX
Codestrong 2012 breakout session at&t api platform and trends
PPTX
Codestrong 2012 breakout session what's new in titanium studio
PPTX
Codestrong 2012 breakout session using appcelerator cloud services in your ...
PPTX
Codestrong 2012 breakout session the role of cloud services in your next ge...
PPTX
Codestrong 2012 breakout session new device platform support for titanium
PPTX
Codestrong 2012 breakout session mobile platform and infrastructure
PPTX
Codestrong 2012 breakout session making money on appcelerator's marketplace
PDF
Codestrong 2012 breakout session live multi-platform testing
PPTX
Codestrong 2012 breakout session leveraging titanium as part of your mobile...
PPTX
Codestrong 2012 breakout session i os internals and best practices
Axway Appcelerator - Titanium SDK 6.1.0 - Status, Releases & Roadmap
2014 Dublin Web Summit by Jeff Haynie
Making the Mobile Mind Shift
Stop Debating, Start Measuring
Mobile & The New Experience Economy (And What it Means for IT)
Apps, APIs & Analytics: What "Mobile First" Really Means
Appcelerator Presentation Template
Codestrong 2012 keynote jonathan rende, appcelerator's vp of products
Codestrong 2012 keynote jeff haynie, appcelerator's ceo
Codestrong 2012 keynote how to build a top ten app
Codestrong 2012 breakout session at&t api platform and trends
Codestrong 2012 breakout session what's new in titanium studio
Codestrong 2012 breakout session using appcelerator cloud services in your ...
Codestrong 2012 breakout session the role of cloud services in your next ge...
Codestrong 2012 breakout session new device platform support for titanium
Codestrong 2012 breakout session mobile platform and infrastructure
Codestrong 2012 breakout session making money on appcelerator's marketplace
Codestrong 2012 breakout session live multi-platform testing
Codestrong 2012 breakout session leveraging titanium as part of your mobile...
Codestrong 2012 breakout session i os internals and best practices

Codestrong 2012 breakout session introduction to mobile web and best practices

  • 1. Introduction to Mobile Web and Best Practices Bryan Hughes, Ph.D. Software Engineer Appcelerator [email protected] 1
  • 2. About Me • Appcelerator Software Engineer in the JavaScript Engineering group • Previously developed the HTML 5 platform at Particle Code • Ph.D. in Electrical Engineering and Computer Science from Texas Tech University 2
  • 4. Titanium Mobile Target • Provides similar experience to Android and iOS • Not intended for integration into existing web apps/frameworks • Designed specifically for mobile browsers and devices 4
  • 5. Single Page Web App • Apps are hosted on traditional web servers • Users use their device‟ browser to navigate to the URL of the app • Apps are a single page only 5
  • 6. Architecture • Uses HTML 5 technologies to implement the Titanium Mobile API • APIs implemented using Asynchronous Module Definition • Everything is require()‟d var ad = require('Ti/UI/AlertDialog'), foo = new ad({ title: 'Mobile Web Rules!' }); foo.show(); 6
  • 7. User Interface • Controls are composites of other controls • Custom layout Ti.UI.View algorithm Ti.UI.View Ti.UI.ImageView Ti.UI.Label 7
  • 8. File System • Pluggable provider architecture • Fully support directories, binary files, etc. 8
  • 9. Miscellany Titanium API HTML/CSS API Ti.Network.HTTPClient XML HTTP Request (XHR) Ti.Accelerometer devicemotion window event navigator.geolocation and deviceorientation Ti.Geolocation window event Touch Gestures touchstart/move/end window events Ti.Media.VideoPlayer <video> HTML tag 9
  • 11. Tiapp.xml Options <analytics> <use-xhr>true, false</use-xhr> </analytics> <filesystem> <backend>Ti/_/Filesystem/Local</backend> <registry>preload</registry> </filesystem> <Instrumentation>true, false</Instrumentation> <precache> <image>image path</image> <include>file path</include> <require>module id</require> <locale>locale code</locale> </precache> <splash> <enabled>true, false</enabled> <inline-css-images>true, false</inline-css- </splash> <theme>theme name (default is „default‟)</theme> 11
  • 12. Splash Screen Created with HTML+CSS 12
  • 13. Icons • Favicon • Apple Web Applications 13
  • 14. Modules • CommonJS – Can only use Titanium APIs – Compatible with Android and iOS • MobileWeb – Can use any browser features – Will not work on Android and iOS 14
  • 15. Hybrid Apps 100% Written in Titanium 15
  • 16. Debugging Debug like any other web page 16
  • 18. Deploying production minifies code function myFunction(parameterOne, parameterTwo) { • Web server var parameterOnePlusFive = parameterOne + 5; agnostic var parameterTwoPlusTen = parameterTwo + 10; } myFunction(5 + 10, 15 - 20); • Deployment: development or production function myFunction(a,b){var x=a+5,d=b+10}myFunction(15,-5) 18
  • 20. Local Storage • Several APIs use Local Storage • 5mb Local Storage per domain • Exception thrown when exceeded 20
  • 21. Cross Domain HTTP if (Ti.Platform.osname === 'mobileweb') { Ti.Network.httpURLFormatter = function (url) { • Access-Control- // Create prefix from server’s hostname var newPrefix = Allow-Origin location.protocol + '//' + location.host + HTTP header (location.port ? ':' + location.port : ''); // Make sure URL isn't relative • Proxy + URL if (url.indexOf(newPrefix) === -1 && url.indexOf('://') !== -1) { formatter url = newPrefix + '/proxy?url=' + url; console.debug('proxying to ' + url); } return url; } } 21
  • 22. WebViews • Cross domain WebViews are limited • Sites with X- Frame-Options set will not load 22
  • 23. Code Limitations • Variables and functions cannot use DOM names • Titanium objects contain many “hidden” fields 23
  • 24. Code Minification function myFunction(parameterOne, parameterTwo) { var parameterOnePlusFive = parameterOne + 5; var parameterTwoPlusTen = parameterTwo + 10; } • Code minification myFunction(5 + 10, 15 - 20); is not code obfuscation • Code/resources function myFunction(a,b){var x=a+5,d=b+10}myFunction(15,-5) cannot be secured in Mobile Web function myFunction(a, b) { var c = a + 5, d = b + 10; } myFunction(15, -5); 24
  • 25. UI Performance • Two layout passes per layout • Browsers are slower than native • Titanium apps that perform well in Android/iOS may not perform well in Mobile Web 25
  • 26. Miscellany • Unsupported APIs – Database – Contacts – AudioPlayer – Sockets • Facebook Site URL must be set • Everything must be loaded over the network! 26
  • 27. Browser Compatibility • Recommended – Mobile Safari 4.2+ – Android 2.2+ – Chrome for Android – Firefox Mobile for Android – BlackBerry 7+, Playbook • Limited Support – Windows Phone 7.5 (Mango) – BlackBerry 6 (Bold) 27
  • 29. Security • Everything in the app is public information • Don‟t trust the client application • Don‟t put private keys in code 29
  • 30. Layout Optimizations • Reduce the number of controls on screen • Only use vertical and horizontal layouts if they are actually needed • Use basic views whenever possible • Use gradients and solid colors instead of images 30
  • 31. Image Optimizations • Compress JPEG: 371 KB images with the correct CODEC PNG: 2.3 MB • Reduce image dimensions • Reduce color JPEG: 10.14 KB depth PNG: 10.08 KB 31
  • 32. Pre-caching • Cache commonly used source code, images, and text files • Images are encoded as data URIs • Cached resources are inlined in index.html 32

Editor's Notes

  • #3: At Appcelerator:* Implemented UI for the Mobile Web platform* Titanium Command Line Interface* Lead for the Titanium Code Processor
  • #6: The browser does not control navigation in the app
  • #7: Custom implementation that supports AMD and CommonJS simultaneouslyPrototypal inheritanceDo not try experiment in practice
  • #8: Ti.UI elements are composites of a combination of HTML elements and other Ti.UI elementsTi.UI.View is the simplest, consisting of a single DIVCustom single-pass, polynomial-based layout algorithmAnimations use matrix3d CSS transforms + requestAnimationFrameSupport for multiple animations on a single element, although none of the other platforms support it
  • #9: Default provider uses Local StorageCustom lightweight file system implemented on top of Local StorageCan create custom providers that use SQL on a server, indexdb, etc
  • #13: Resources/mobileweb/splash/splash.html - HTML fragmentsplash.css – splash.html CSS
  • #14: Favicon:Resources/mobileweb/appicon.pngApple web applications: Resources/mobileweb/apple_startup_images
  • #15: Mobile Web:Must be AMD modulesDo not recommend using UI libraries such as jQuery or Sensa Touch due to conflicts
  • #16: Android/iOS app as parent containerMobile Web app as child content
  • #17: WebKit Inspector, Firebug, F12 Tools, etc in Desktop browserWeb Inspector in iOS 6adblogcat and about:debug in Android Browser
  • #18: Logs instrumentation data to the consoleEnabled in tiapp.xml
  • #19: Place the contents of build/mobileweb in the web server’s document rootMinified using uglify-js
  • #21: Filesystem, Ti.App.Properties, analytics, and others share Local StorageSites installed to the home screen, etc typically get unlimited storageStoring images and other binary data quickly eats up available space
  • #22: Access-Control-Allow-Origin is set on the serverDo not want to set to * in production for security reasonsIf using a proxy, need to secure proxy against nefarious agents
  • #23: Many methods do not work and some properties are unavailable if the source is cross domainGoogle, Facebook, Twitter, and others set X-Frame-Options
  • #24: Example DOM names: window, document, event, location, navigator, parent, screen, selfVaries from browser to browserOverwriting hidden fields can break the appExample fields: properties, constants, constructor, _parent, _childrenRecommend not adding fields to Titanium objects, instead create a wrapper classScreenshot is of the global namespace in Chrome
  • #25: Minified code can be easily reverse engineeringMinification is used to decreasing load times
  • #26: First layout pass is our algorithm, second is browser reflowDesktop web can even be slower than native mobile in some cases
  • #27: Facebook apps must have their Site URL set to the web server via developer.facebook.com
  • #28: Windows Phone 7.5 does not support touch events, so scrolling is not supportedBlackberry 6 supports all the necessary features, but it so slow as to be unusable in most cases
  • #30: Application can be spoofed by malicious actorsScreenshot is of minified source codeCaptured via WebKit InspectorBeautified using jsbeautifier.org
  • #31: Buttons contain 6 elements, but views only contain 1 elementViews receive the same events as buttonsPerformance of gradients vs images is flipped on Mobile Web compared to iOS
  • #32: Natural images such as photographs should be compressed using JPEGStructural images such as graphs and text should be compressed using PNGImage dimensions should be as low as tolerableColor depth should be as low as tolerable
  • #33: InliningSubstantially reduces the number of HTTP requestsLoad time when resource is requested is very fastCaching increases in-app performance at the expense of startup time
  • #34: Too Text HeavyShorten