This document was uploaded by user and they confirmed that they have the permission to share
it. If you are author or own the copyright of this book, please report to us by using this DMCA
report form. Report DMCA
Overview
Download & View Demo Lab 1_tasneem Sayeed_symbian Foundation as PDF for free.
Tasneem Sayeed Technical Lead, Web Tools Platforms October 27, 2009
Outline
Definition of Mobile Web Mobile Device Constraints Mobile Development Challenges SEE 2009 Widget Demo Walkthrough Sending AJAX Requests and Retrieving Data Performance Rules & Mobile Web Development Strategies Bridging the Mobile Web Tools Gap Conclusion
Definition of the Mobile Web “Mobile Web” W3C pushing the idea of “One Web” Making the same information and services available to users irrespective of the device they are using Does not mean exactly the same information is available in exactly the same representation across all devices The context of mobile use, device capability variations, bandwidth issues and mobile network capabilities all affect the representation Some services and information better suited for and targeted at particular user contexts
Screen Size/Resolution Keep Layout as simple and fluid as possible Keep your page contents all in a single column stacked on top of each other so regardless of screen size/resolution, information simply wraps Test with and without CSS and JavaScript
Mobile Device Constraints •
•
Limited Memory • Limits amount of processing that can be handled Limited battery power • Limits implementations of JavaScript, Flash and other technologies • Drains battery • Creates a slower user experience • Increases the bandwidth (i.e. can be more costly to download web content)
“Code once, run anywhere” is a foreign concept Many browser and device types to accommodate Unresolved connectivity and caching issues to contend On our 5th Generation of HTML with WML, XHTML, and cHTML still alive Constellation of mobile platforms • Symbian (Symbian OS-based) • Java ME • BREW • Windows Mobile • Blackberry • iPhone (Objective-C based) • Linux-based Android • Palm Web OS • and more on the way!
Web Runtime (WRT) for S60 devices • A set of components based on the WebKit architecture that enables you to apply your skills at creating web content – to create full mobile web applications that are simple, powerful and optimized for mobile devices • Widget development is simplified with plug-ins for Aptana Studio, Adobe Dreamweaver, and Microsoft Visual Studio • The plug-ins enable developers to create, edit, test, package and deploy widgets all from within their web development tool of their choice
For more information:: http://www.forum.nokia.com/Technology_Topics/Web_Technologies/Web_Runtime/ / See Mobile 2.0 Developer Talk on “Developing Web Runtime Widgets with Aptana”
Sending AJAX Requests using Twitter API // Twitter API for getting a user’s RSS feed var twitterurl = "http://twitter.com/statuses/user_timeline/TwitMyMobile.rss"; // Get the rss feed // Prepare for asynchronous download this.http = new Ajax(); // true means asynchronous request this.http.open("GET", twitterurl , true); // When the AJAX request is done, it will call self.DoUpdate() this.http.onreadystatechange = function() { self.DoUpdate(); }; // send the AJAX request this.http.send(null);
Parsing the RSS Data: DoUpdate() Twitter.prototype.DoUpdate = function(){ if (this.http.readyState == 4) { try { // Get parsed Doc var xmlDoc = this.http.responseXML; if (xmlDoc == null) { // if the content type is not set correctly, // we get the response as text var xmlparser = new DOMParser(); xmlDoc = xmlparser.parseFromString(this.http.responseText, "text/xml"); } var itemElements = xmlDoc.getElementsByTagName("item"); var loopEnd = Math.min(this.numToShow, itemElements.length); // traverse elements and create buttons for (var i = 0; i < loopEnd; i++) { // iterate through child nodes of this item // and gather tweets var title = null; var date = null;
Parsing the RSS Data: DoUpdate() node = itemElements[i].firstChild; while (node != null) { if (node.nodeType == Node.ELEMENT_NODE){ if (node.nodeName == "title") { // item title title = getTextOfNode(node); } else if (node.nodeName == "pubDate" || node.nodeName == "dc:date") { // item publishing date date = getTextOfNode(node); } } end while node = node.nextSibling; } // end for this.buttons[i].setText("" + date + " " + title + ""); this.buttons[i].setImage("tweet.png"); } // end if (xmldoc == null) } // end try
Parsing the RSS Data: DoUpdate() catch (x) { this.buttons[0].setText( "Uh-Oh! Tweetz right now.");
not tweeting
for (var i = 0; i < this.numToShow; i++) { this.buttons[i].setText(""); this.buttons[i].setImage(null); } // end for } // end catch } // if (this.http.readyState == 4) { }
Parsing the data: getTextofNode() // Returns the text of a node. function getTextOfNode(node) { var buf = ""; // iterate through all child elements and // collect all text to the buffer var child = node.firstChild; while (child != null) { if (child.nodeType == Node.TEXT_NODE || child.nodeType == Node.CDATA_SECTION_NODE) { // append text to buffer if (buf != "") { buf += " "; } buf += child.nodeValue; } child = child.nextSibling; } // make link if there is a url var ind = buf.indexOf("http://"); var endind = buf.indexOf(" ", ind); if ( ind != -1 ) { var tmp = buf.substring(0,ind); var url = "";
Make Fewer HTTP Requests Use a Content Delivery Network Add an Expires Header (or Cache-control) GZip Components Put CSS (Stylesheets) at the Top Move Scripts to the Bottom (inline too) Avoid CSS Expressions CSS Make JavaScript and CSS External Reduce DNS Lookups Minify JavaScript and CSS (inline too) CSS Avoid Redirects Remove Duplicate Scripts Configure ETags Make AJAX Cacheable
When you send zipped content over the internet, the browser unpacks it Modern browsers understand compressed content Request header Accept-Encoding:gzip,deflate Response header Content-Encoding: gzip All text components should be sent gzipped: html (php), js, css, xml, txt…
Firefox and IE will not render anything until the last piece of CSS reaches the wire Place stylesheets as early as possible in the document Your page here
Performance Rules: Move Scripts to the Bottom (inline too) • •
•
Scripts block downloads Since the script can do location.href or document.write at any time, browser blocks rather than downloading possibly useless components Inline scripts too <script src=“script.js” …/>