Ajax Design Principles and Patterns

Beyond the "Cool" Factor: Real-World Ajax

Michael Mahemoff

Independent

This presentation - along with the notes you're reading - are powered by Eric Meyer's S5. For the full multimedia version, please visit http://ajaxpatterns.org/ae2006.

Cool web51t3, Dude

Sure, Ajax gives you ...

Cool Buzzworthy Sexy Effects Dynamic Modern Rich GetIt Flashy Visual Show Me The Money GUI Web 2.0 Animated DHTML

Keeping it Real

But what about ...

Usable Productive Useful Fun Achievable Intuitive Robust Practical Quick Responsive Maintainable Accurate Feature-Driven

"Impossible ... It's all so new"

Reinventing the Wheel?

People encounter similar problems ...

... Leading to similar solutions

 

Learning from the Past

Ajax isn't that new



 

Usability Principles

Follow Web Standards

The Browser is Not a Desktop

If it's Different, Make it Really Different

Usability Principles

Ensure Smooth, Continuous, Interaction

Provide Affordances

Usability Principles

Support Customisation

Make it Fun

 

Software Design/Architecture Principles

Embrace Javascript

Accept Workarounds Where Necessary

"Ajax is a Hack"
"Band-Aid Solution"
"Duct Tape"

Software Design/Architecture Principles

Partition into Multiple Tiers

Develop for Compatibility

Software Design/Architecture Principles

Reduce Bandwidth

Deal with Latency

Software Design/Architecture Principles

Tame Asynchrony

Software Design/Architecture Principles

Go Easy on the Browser

Software Design/Architecture Principles

Practice Graceful Degradation

Ajax Patterns

Online at AjaxPatterns.org

Currently ~70 Ajax Patterns

Refactoring and Ajaxifying

Ajax Patterns

Foundational Technology Patterns (11)

Programming Patterns (23)

Functionality and Usability Patterns (28)

Development/Practice Patterns (8)

Patterns that Compete

Better Conflict Resolution through the Judicious Application and Objective Matrix-Driven Comparison of the Ajax Patterns

AKA

Pattern Smackdown

Ajax Deluxe vs Ajax Lite I

Ajax Lite

Web App after Ajaxification.
AKA "Website", "HTML++"

Ajax Lite: Amazon Tags

Ajax Deluxe

Ajax to the max.
AKA "Web App", "Client/SOA"

Ajax Deluxe: Writely

Ajax Deluxe vs Ajax Lite II

Ajax Lite

+ Graceful degradation

+ Low risk - familiar to existing users

+ Smooth migration

Ajax Deluxe

+ Desktop substitute

+ Architect's dream - Complete model-view separation

+ Web services momentum

+ Performant - small payloads

XMLHttpRequest Call vs IFrame Call

XMLHttpRequest Call

Object dedicated to remoting

+ Purpose-built

+ Extra functionality, e.g. abort(), onreadystatechange

+ People (erroneously) equate it with "Ajax"

+ Well-understood

May be Faster for small responses

IFrame Call

Set the IFrame's source, then grab the response

+ Broader compatibility

+ Browser history, Back button (Unique URL pattern)

+ May be more suited to HTTP Streaming

May be Faster for long responses

XMLHttpRequest Call vs IFrame Call

XMLHttpRequest Call

Object dedicated to remoting

+ Purpose-built

+ Extra functionality, e.g. abort(), onreadystatechange

+ People (erroneously) equate it with "Ajax"

+ Well-understood

May be Faster for small responses

IFrame Call

Set the IFrame's source, then grab the response

+ Broader compatibility

+ Browser history, Back button (Unique URL pattern)

+ May be more suited to HTTP Streaming

May be Faster for long responses

Semantic Message vs HTML Message

Semantic Message (Plain-Text, XML, JSON)

Browser downloads raw structure, then parses/stores/displays

HTML Message (AKA "AHAH")

Browser downloads HTML, then sticks onto page with innerHTML.

Semantic Message vs HTML Message

Semantic Message (Plain-Text, XML, JSON)

+ Shorter message

+ Can retain structure for local processing

+ Plug into web services

+ Easier to test service

+ Cleaner model-view Separation

HTML Message (AKA "AHAH")

+ Longer message, but less processing time

+ Easier graceful degradation

+ Can generate from server-side library

+ Less Javascript/DOM knowledge required

XML Message Vs JSON Message

XML Message

XML: Standard industry message format

JSON Message

JSON: Lightweight, raw, alternative to XML

XML Message Vs JSON Message

XML Message

+ Familiar, popular, "no-one ever got fired for choosing XML..."

+ Self-documenting

+ Surrounding standards (XSLT, XPath, etc.)

+ Broader tool/framework support

+ May be faster to parse

JSON Message

+ Smaller payload

+ Simpler structure

+ Concrete format, akin to an XML dialect

+ Broader compatibility

+ May be faster to parse

Periodic Refresh Vs HTTP Streaming

Periodic Refresh (AKA "Pull", "Poll")

Keep checking for server changes

HTTP Streaming (AKA "Push", "Comet")

Long-lived connection keeps pumping out new data.

Periodic Refresh Vs HTTP Streaming

Periodic Refresh (AKA "Pull", "Poll")

+ Simple, straightforward, familiar
+ Portable across browsers and servers
+ Can include data inside request
+ Easy to test
+ Leverages caching
+ More efficient if data changes are infrequent

HTTP Streaming (AKA "Push", "Comet")

Responsive + Stable profile
+ Less connection establishing overhead
- Need specialised server
- Need conforming proxies
- Browser might not expose data until connection closed
- Browser memory problems

Future Trends

Javascript patterns and idioms

Libraries, Frameworks, Patterns (Yahoo!)

New technologies: Local storage, SVG, XForms, WHAT-WG Controls

Browser trends

[Extra] Patterns and Demos

Functionality

Unique URL

Heartbeat

Timeout

Host-Proof Hosting

[Extra] Patterns and Demos

Performance Optimisation

Browser-Side_Cache

Predictive Fetch

Multi-Stage Download

Guesstimate

Host-Proof Hosting