Welcome!

Machine Learning Authors: Elizabeth White, Liz McMillan, Jack Jachner, Pat Romanski, Progress Blog

Related Topics: Machine Learning

Machine Learning : Article

Real-World AJAX Book Preview: AJAX Design Considerations

Real-World AJAX Book Preview: AJAX Design Considerations

This content is reprinted from Real-World AJAX: Secrets of the Masters published by SYS-CON Books. To order the entire book now along with companion DVDs for the special pre-order price, click here for more information. Aimed at everyone from enterprise developers to self-taught scripters, Real-World AJAX: Secrets of the Masters is the perfect book for anyone who wants to start developing AJAX applications.

AJAX Design Considerations
In the previous section, we laid out the design considerations for mobile Web applications as recommended by the W3C. Here we'll discuss AJAX-specific considerations.

As we know, AJAX is not a new technology. It's a collection of existing technologies put together in a different way. Thus, designing a mobile AJAX application is similar to designing a mobile Web application.

Performance becomes far more critical. While application performance is critical on the Web, it becomes much more severe in a mobile Web environment. Also widget design using AJAX needs some special thought.

Since the synergy between mobile widgets and AJAX is central to our vision, we'll focus on widgets in greater detail. In the next section, we will use some of the principles outlined here to develop some widget code.

To recap, the elements comprising AJAX are

  • XHTML and CSS
  • Document Object Model
  • XML and XSLT
  • XMLHttpRequest for asynchronous data retrieval
  • JavaScript
Of these, potentially, the elements that could be optimized from a developer standpoint include JavaScript constructs, DOM, and CSS. Even in these cases, the same principles apply as per the Web. Hence we won't discuss them in great detail.

Note that you have to consider all the elements discussed in the previous sections (the W3C recommendations) to ensure that the AJAX application works well.

General Browser/Mobile-Level Recommendations

  • Don't load more documents than you have to.
  • Avoid keeping references alive from one document to another.
  • A window's history grows if you keep loading documents into it. When the user moves, the document may not be reloaded and reinitialized.
  • Be aware of device limitations like little memory, low-powered CPUs, slow disk access, etc.
  • Reflows and repaints are very expensive.
  • Timer resolution is unpredictable on a mobile device.
Notes
  1. Trim libraries of unneeded code.
  2. Minimize use of iframe/object type="text/html".
  3. When removing an iframe/object, also set any references in script to null.
  4. Don't use scripts (including event handlers) on documents that don't require them.
  5. Avoid tight-timed loops whenever possible. setInterval( funcRef, 0) is a no-no, setInterval(funcRef, 50) is okay.
  6. Carefully evaluate whether you want to use any patterns for adding to the browser history.
  7. Use single-image rollovers, www.tutorio.com/tutorial/pure-css-image-rollovers.
JavaScript Constructs
  • Don't use "eval" or the Function constructor if you can avoid it.
  • Don't use "with" if you can avoid it.
  • Don't use "try-catch-finally" inside performance-critical functions.
  • Don't use global variables if you can avoid them.
  • Be mindful of implicit object conversion, especially on strings.
  • Avoid for-in in performance-critical functions.
Notes
  1. Isolate uses of eval, with, and try-catch-finally inside top-level functions. Almost every use of eval can be rewritten without eval, and the resulting code will be faster and cleaner.
  2. Use strings accumulator-style: a += "x"; a += "y"; is better than a += "x" + "y".
  3. Convert primitive values to objects explicitly if you're using them as objects a lot.
  4. Primitive operations can be faster than function calls: a<b ? a : b instead of Math.min(a,b).
  5. Keep array objects dense; if you need a hash table, use an object instead.
  6. Pass functions, not strings, to setTimeout() and setInterval().
  7. Avoid properties that are re-evaluated in scripts: for (var i = prop.length; i--;) is faster than for (var i=0; i++ < prop.length;).
DOM
  • Document tree modification will trigger reflow.
  • Modifying CSS properties other than backgrounds and colors very likely triggers reflows.
  • Don't modify a document while traversing an element collection.
  • Avoid manual traversal of the document tree.
  • Avoid inspecting large numbers of nodes.
  • Timeouts may not be strictly honored.
Notes
  1. Set individual .style properties.
  2. Don't change Element.id or Element.className.
  3. Cache DOM values in script variables when you can.
  4. Make a small number of large changes to the document tree, not a large number of small changes.
  5. Use document fragments to build subtrees that are to be inserted. Build the entire tree before inserting it.
  6. Perform modifications by accumulating nodes to be altered during a traversal phase and follow it with a modification phase.
CSS Optimization
  • Screen sizes are relatively predictable, but vary a lot. There are 176, 384, 480, 640 in pixel width.
  • Device DPI can vary from 100 to over 200.
  • All fonts may not be available.
  • CSS selectors affect performance.
Tricks
  1. Use CSS3 media queries: @media handheld and (device-width: 384px) { /* Rules for device*/ }.
  2. Use generic font families.
  3. Be careful with font sizing. What's readable on a 100dpi-device may be nearly invisible on a 200dpi device.
  4. Use concise CSS selectors: "div > p" over "div p" if what you mean is "div > p".
  5. Avoid duplicate CSS rules.
Widget Design

A widget is a small Web application that runs directly on a user's desktop. It is usually focused on doing a single task. Technically developing a widget is similar to developing a Web page except that the widget functions like an application and lives directly on the desktop.

Widgets are chromeless applications and will run without regular user interface elements such as normal browser controls, like the back button or address bar. An example of a widget is the clock widget.

AJAX technology facilitates building widgets. As I've mentioned before, the advantage of widgets (especially when developed using the Opera platform) is that the same code can be used on the desktop, browser, and mobile device with basic modifications.

For purposes of our discussion, we'll focus on widgets using AJAX technologies. Widgets use HTML, JavaScript, and CSS and can use other technologies such as SVG. Widgets have a configuration file and are packaged in the ZIP format and have their extension renamed .wdgt.

Because a widget is a small application, it's focused on a simple task. Note that in environments like the Opera browser, widgets can call other widgets. Hence, more complex applications can be developed using the widget's philosophy. However, for now, let's look only at simple widgets. Also, note that widgets should be self-contained, i.e.. they shouldn't stop working when the widget is online.

The Opera Platform
As we have seen before, we need an AJAX framework on the device and access to device APIs to create a useful mobile application. This function is performed by the Opera platform, which acts as an SDK and a framework for AJAX mobile applications.

The Opera Platform is comprised of:

  • An Opera Web browser running in full-screen mode
  • An AJAX framework for running multiple widgets/applications
    - Access the DOM and the phone's native functionality through an abstraction layer (APIs)
The tools needed to create a widget are the same as needed for regular Web development, i.e., a basic understanding of Web technologies; a text editor or Web IDE that allows creating JavaScript, HTML, and CSS files; and a tool for creating and maintaining .zip archives.

At the moment, Opera widgets can be published on the My Opera community or you could deploy the widget in your own environment. Although widgets are similar to Web pages, there are some differences.

Note these apply to the Opera environment but can illustrate general widget development:

  • The widget lives outside the Web browser directly on the user's desktop without any of the regular user interface elements such as title bars.
  • The widget's security restrictions are different from regular Web pages, enabling you to create a widget that will simultaneously interface with different Web Services living on different Web servers.
  • Widgets have a widget object available from JavaScript that lets an author access widget-specific functionality.
  • A widget has access to permanent storage for its settings and downloaded data. This mechanism is similar to cookies, but the storage capacity is larger than for cookies and does not automatically expire after a given time.
  • Widgets typically have several views available in the same document. One of these views is what a widget user typically sees when using the widget, and another one is where you provide the user with configuration options. Switching between these views is done by performing transitions on the views using regular JavaScript+CSS methods.
  • By default a widget is draggable so the user can move it around on the screen simply by clicking and dragging the widget. If this behavior isn't desired for parts of a widget, the user will have to specify control regions where the widget doesn't respond to dragging.

This content is reprinted from Real-World AJAX: Secrets of the Masters published by SYS-CON Books. To order the entire book now along with companion DVDs, click here to order.

More Stories By Ajit Jaokar

Ajit Jaokar is the author of the book 'Mobile Web 2.0' and is also a member of the Web2.0 workgroup. Currently, he plays an advisory role to a number of mobile start-ups in the UK and Scandinavia. He also works with the government and trade missions of a number of countries including South Korea and Ireland. He is a regular speaker at SYS-CON events including AJAXWorld Conference & Expo.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


@CloudExpo Stories
Blockchain is a shared, secure record of exchange that establishes trust, accountability and transparency across business networks. Supported by the Linux Foundation's open source, open-standards based Hyperledger Project, Blockchain has the potential to improve regulatory compliance, reduce cost as well as advance trade. Are you curious about how Blockchain is built for business? In her session at 21st Cloud Expo, René Bostic, Technical VP of the IBM Cloud Unit in North America, will discuss th...
The question before companies today is not whether to become intelligent, it’s a question of how and how fast. The key is to adopt and deploy an intelligent application strategy while simultaneously preparing to scale that intelligence. In her session at 21st Cloud Expo, Sangeeta Chakraborty, Chief Customer Officer at Ayasdi, will provide a tactical framework to become a truly intelligent enterprise, including how to identify the right applications for AI, how to build a Center of Excellence to ...
Internet of @ThingsExpo, taking place October 31 - November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA, is co-located with 21st Cloud Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. The Internet of Things (IoT) is the most profound change in personal and enterprise IT since the creation of the Worldwide Web more than 20 years ago. All major researchers estimate there will be tens of billions devic...
While some vendors scramble to create and sell you a fancy solution for monitoring your spanking new Amazon Lambdas, hear how you can do it on the cheap using just built-in Java APIs yourself. By exploiting a little-known fact that Lambdas aren’t exactly single-threaded, you can effectively identify hot spots in your serverless code. In his session at @DevOpsSummit at 21st Cloud Expo, Dave Martin, Product owner at CA Technologies, will give a live demonstration and code walkthrough, showing how ...
As DevOps methodologies expand their reach across the enterprise, organizations face the daunting challenge of adapting related cloud strategies to ensure optimal alignment, from managing complexity to ensuring proper governance. How can culture, automation, legacy apps and even budget be reexamined to enable this ongoing shift within the modern software factory?
SYS-CON Events announced today that Elastifile will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 - Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Elastifile Cloud File System (ECFS) is software-defined data infrastructure designed for seamless and efficient management of dynamic workloads across heterogeneous environments. Elastifile provides the architecture needed to optimize your hybrid cloud environment, by facilitating efficient...
There is only one world-class Cloud event on earth, and that is Cloud Expo – which returns to Silicon Valley for the 21st Cloud Expo at the Santa Clara Convention Center, October 31 - November 2, 2017. Every Global 2000 enterprise in the world is now integrating cloud computing in some form into its IT development and operations. Midsize and small businesses are also migrating to the cloud in increasing numbers. Companies are each developing their unique mix of cloud technologies and service...
@DevOpsSummit at Cloud Expo taking place Oct 31 - Nov 2, 2017, at the Santa Clara Convention Center, Santa Clara, CA, is co-located with the 21st International Cloud Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. The widespread success of cloud computing is driving the DevOps revolution in enterprise IT. Now as never before, development teams must communicate and collaborate in a dynamic, 24/7/365 environment. There is ...
SYS-CON Events announced today that Golden Gate University will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Since 1901, non-profit Golden Gate University (GGU) has been helping adults achieve their professional goals by providing high quality, practice-based undergraduate and graduate educational programs in law, taxation, business and related professions. Many of its courses are taug...
DevOps at Cloud Expo, taking place October 31 - November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA, is co-located with 21st Cloud Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. The widespread success of cloud computing is driving the DevOps revolution in enterprise IT. Now as never before, development teams must communicate and collaborate in a dynamic, 24/7/365 environment. There is no time to w...
With Cloud Foundry you can easily deploy and use apps utilizing websocket technology, but not everybody realizes that scaling them out is not that trivial. In his session at 21st Cloud Expo, Roman Swoszowski, CTO and VP, Cloud Foundry Services, at Grape Up, will show you an example of how to deal with this issue. He will demonstrate a cloud-native Spring Boot app running in Cloud Foundry and communicating with clients over websocket protocol that can be easily scaled horizontally and coordinate...
SYS-CON Events announced today that DXWorldExpo has been named “Global Sponsor” of SYS-CON's 21st International Cloud Expo, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Digital Transformation is the key issue driving the global enterprise IT business. Digital Transformation is most prominent among Global 2000 enterprises and government institutions.
SYS-CON Events announced today that Grape Up will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct. 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Grape Up is a software company specializing in cloud native application development and professional services related to Cloud Foundry PaaS. With five expert teams that operate in various sectors of the market across the U.S. and Europe, Grape Up works with a variety of customers from emergi...
From 2013, NTT Communications has been providing cPaaS service, SkyWay. Its customer’s expectations for leveraging WebRTC technology are not only typical real-time communication use cases such as Web conference, remote education, but also IoT use cases such as remote camera monitoring, smart-glass, and robotic. Because of this, NTT Communications has numerous IoT business use-cases that its customers are developing on top of PaaS. WebRTC will lead IoT businesses to be more innovative and address...
21st International Cloud Expo, taking place October 31 - November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA, will feature technical sessions from a rock star conference faculty and the leading industry players in the world. Cloud computing is now being embraced by a majority of enterprises of all sizes. Yesterday's debate about public vs. private has transformed into the reality of hybrid cloud: a recent survey shows that 74% of enterprises have a hybrid cloud strategy. Me...
In his session at 20th Cloud Expo, Scott Davis, CTO of Embotics, discussed how automation can provide the dynamic management required to cost-effectively deliver microservices and container solutions at scale. He also discussed how flexible automation is the key to effectively bridging and seamlessly coordinating both IT and developer needs for component orchestration across disparate clouds – an increasingly important requirement at today’s multi-cloud enterprise.
DevOps at Cloud Expo, taking place October 31 - November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA, is co-located with 21st Cloud Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. The widespread success of cloud computing is driving the DevOps revolution in enterprise IT. Now as never before, development teams must communicate and collaborate in a dynamic, 24/7/365 environment. There is no time to w...
Vulnerability management is vital for large companies that need to secure containers across thousands of hosts, but many struggle to understand how exposed they are when they discover a new high security vulnerability. In his session at 21st Cloud Expo, John Morello, CTO of Twistlock, will address this pressing concern by introducing the concept of the “Vulnerability Risk Tree API,” which brings all the data together in a simple REST endpoint, allowing companies to easily grasp the severity of t...
Recently, WebRTC has a lot of eyes from market. The use cases of WebRTC are expanding - video chat, online education, online health care etc. Not only for human-to-human communication, but also IoT use cases such as machine to human use cases can be seen recently. One of the typical use-case is remote camera monitoring. With WebRTC, people can have interoperability and flexibility for deploying monitoring service. However, the benefit of WebRTC for IoT is not only its convenience and interopera...
Any startup has to have a clear go –to-market strategy from the beginning. Similarly, any data science project has to have a go to production strategy from its first days, so it could go beyond proof-of-concept. Machine learning and artificial intelligence in production would result in hundreds of training pipelines and machine learning models that are continuously revised by teams of data scientists and seamlessly connected with web applications for tenants and users.