Home > Store

Advanced Ajax: Architecture and Best Practices

Register your product to gain access to bonus material or receive a coupon.

Advanced Ajax: Architecture and Best Practices

Book

  • Sorry, this book is no longer in print.
Not for Sale

Description

  • Copyright 2008
  • Edition: 1st
  • Book
  • ISBN-10: 0-13-135064-1
  • ISBN-13: 978-0-13-135064-9

“I very much enjoyed how this book covers the full Ajax application lifecycle and not only coding techniques. Anyone who is looking to become a professional front-end developer will appreciate the architectural insight and best practices delivered by this book.”  — Andi Gutmans, Co-Founder & Co-Chief Technology Officer of Zend Technologies

Mission-Critical Ajax: Maximizing Scalability, Performance, Security, Reliability, and Maintainability

 

Advanced Ajax: Architecture and Best Practices is the definitive guide to building business-critical, production-quality Web applications with Ajax. Shawn M. Lauriat systematically addresses the design, architecture, and development issues associated with Ajax, offering proven patterns and robust code examples available in no other book. You’ll find best practices for addressing the full spectrum of issues enterprise Ajax developers face: scalability, performance, security, reliability, flexibility, maintainability, and reusability.

Writing for experienced Web developers, Lauriat delivers fresh ideas and elegant solutions: meaty technical content, presented with exceptional clarity. Among the many topics he covers in unprecedented depth: cleanly implementing JavaScript custom events to reduce coupling and to enhance flexibility; overcoming Ajax’s traditional accessibility limitations; reducing network latency through compression and other techniques; and much more. Coverage includes 

  • Planning Ajax interfaces for simplicity, clarity, and intuitiveness
  • Creating scalable, maintainable architectures for client-side JavaScript
  • Using the latest tools to profile, validate, and debug client-side code
  • Architecting the server side for security and functionality, while restricting loaded data, objects, and actions to current requests
  • Protecting against the most widespread and significant Ajax security risks
  • Optimizing every component of an Ajax application, from server-side scripts to database interactions
  • Introducing cutting-edge Ajax: game development, Ajax with canvas, and Ajax for enterprise applications

About the Web Site

This book’s companion Web site (http://advancedajax.frozen-o.com) doesn’t just provide all the code: It shows code examples in action, as building blocks of a real Web application interface.

Sample Content

Online Sample Chapter

Scaling and Maintaining Ajax

Table of Contents

Acknowledgments ......................................................................................................... xiii

About the Author ............................................................................................................xv

Introduction ............................................................................................... 1

0.1 Ajax, the Acronym .............................................................................. 2

    0.1.1 Asynchronous.......................................................................... 3

    0.1.2 JavaScript ................................................................................ 3

    0.1.3 XML ....................................................................................... 4

0.2 This Book’s Intentions ........................................................................ 5

0.3 Prerequisites for This Book ................................................................. 8

Chapter 1 Usability ................................................................................................11

1.1 Interface Versus Showcase ................................................................. 12

    1.1.1 Implementation .................................................................... 14

1.2 User Expectations ............................................................................. 16

1.3 Indicators and Other Forms of User Feedback .................................. 17

    1.3.1 The Throbber ........................................................................ 17

    1.3.2 Progress Indicators ................................................................ 20

    1.3.3 Keeping the User in the Loop ................................................ 22

1.4 Semantic Markup ............................................................................. 30    

    1.4.1 More Accessible ..................................................................... 30

    1.4.2 Easier to Use ......................................................................... 32

    1.4.3 Easier to Maintain ................................................................. 33

    1.4.4 Easier to Parse ....................................................................... 34

1.5 What CSS and JavaScript Have in Common .................................... 37

Chapter 2 Accessibility ..........................................................................................43

2.1 WCAG and Section 508 ................................................................... 44

    2.1.1 WCAG ................................................................................ 45

    2.1.2 Section 508 ........................................................................... 51

2.2 Screen Readers Can Handle Ajax ...................................................... 53

    2.2.1 Content Replacement ........................................................... 54

    2.2.2 Form Validation .................................................................... 55

2.3 Unobtrusive Ajax .............................................................................. 56

2.4 Designing with Accessibility in Mind ................................................ 58

    2.4.1 High-Contrast Design ........................................................... 59

    2.4.2 Zoomable Interface ............................................................... 60

    2.4.3 Easily Targeted Controls ........................................................ 62

2.5 WAI-ARIA ........................................................................................ 63

Chapter 3 Client-Side Application Architecture ....................................................67

3.1 Objects and Event Triggering ............................................................ 68

    3.1.1 Native Object Event Handling .............................................. 70

    3.1.2 JavaScript Objects ................................................................. 71

3.2 Model-View-Controller Design Pattern ............................................ 87

    3.2.1 The Model ............................................................................ 88

    3.2.2 The View .............................................................................. 92

    3.2.3 The Controller .................................................................... 101

3.3 Event-Driven Application Development ......................................... 104

    3.3.1 Advantages of Architecture .................................................. 104

Chapter 4 Debugging Client-Side Code ..............................................................107

4.1 Validation, Validation, Validation .................................................... 108

    4.1.1 Markup Validator ................................................................ 109

    4.1.2 CSS Validator ...................................................................... 110

    4.1.3 Semantic Extractor .............................................................. 111

4.2 Browser Tools and Plugins .............................................................. 111

    4.2.1 The Console ........................................................................ 112

    4.2.2 Internet Explorer ................................................................. 113

    4.2.3 Firefox ................................................................................. 116

    4.2.4 Opera .................................................................................. 122

    4.2.5 Safari ................................................................................... 124

4.3 JavaScript Profiling ......................................................................... 126

    4.3.1 Recognizing Bottlenecks ...................................................... 128

4.4 Unit Testing .................................................................................... 132

    4.4.1 Assertions ............................................................................ 134

    4.4.2 Test Setup ............................................................................ 135

    4.4.3 The Test Itself ...................................................................... 137

    4.4.4 Mock Objects ...................................................................... 140

    4.4.5 Test Suites ........................................................................... 143

Chapter 5 Performance Optimization ..................................................................145

5.1 Database Performance ..................................................................... 146

    5.1.1 Schema ............................................................................... 146

    5.1.2 Queries ............................................................................... 150

5.2 Bandwidth and Latency .................................................................. 154

    5.2.1 Bandwidth .......................................................................... 154

    5.2.2 Latency ............................................................................... 158

5.3 Cache.............................................................................................. 160

    5.3.1 Filesystem............................................................................ 161

    5.3.2 Memory .............................................................................. 163

    5.3.3 Completing the Implementation ......................................... 170

5.4 Taking Advantage of HTTP/1.1 ..................................................... 171

    5.4.1 If-Modified-Since ................................................................ 174

    5.4.2 Range .................................................................................. 176

5.5 PHP Profiling ................................................................................. 178

    5.5.1 Advanced PHP Debugger .................................................... 179

    5.5.2 Xdebug ............................................................................... 182

Chapter 6 Scalable, Maintainable Ajax ................................................................187

6.1 General Practices ............................................................................. 188

    6.1.1 Processor Usage ................................................................... 188

    6.1.2 Memory Usage .................................................................... 191

6.2 A Multitude of Simple Interfaces .................................................... 194

    6.2.1 Modularity .......................................................................... 195

    6.2.2 Late Loading ....................................................................... 198

6.3 Dense, Rich Interfaces .................................................................... 201    

    6.3.1 Monolithic Applications ...................................................... 201

    6.3.2 Preloading ........................................................................... 204

Chapter 7 Server-Side Application Architecture ..................................................207

7.1 Designing Applications for Multiple Interfaces ............................... 208

7.2 Model-View-Controller Design Pattern .......................................... 212

    7.2.1 The Model .......................................................................... 212

    7.2.2 The Controller .................................................................... 222

    7.2.3 The View ............................................................................ 231

7.3 Using the Factory Pattern with Your Template Engine .................... 237

Chapter 8 Keeping a Web Application Secure ......................................................243

8.1 HTTPS .......................................................................................... 244

    8.1.1 Why Use HTTPS? .............................................................. 245

    8.1.2 Security Versus Performance ................................................ 247

8.2 SQL Injection ................................................................................. 247

    8.2.1 Don’t Use Magic Quotes ..................................................... 248

    8.2.2 Filtering .............................................................................. 249

    8.2.3 Prepared Statements ............................................................ 251

8.3 XSS ................................................................................................. 252

    8.3.1 Escaping for Markup ........................................................... 252

    8.3.2 Escaping for URLs .............................................................. 257

8.4 CSRF .............................................................................................. 258

    8.4.1 Check the Referer ................................................................ 259

    8.4.2 Submit an Additional Header .............................................. 261

    8.4.3 Secondary, Random Tokens ................................................. 262

8.5 Don’t Trust the User ........................................................................ 265

8.6 Don’t Trust the Server ..................................................................... 266

Chapter 9 Documenting ......................................................................................271

9.1 Yes, You Need to Document ........................................................... 272

    9.1.1 Jog Your Own Memory ....................................................... 272

    9.1.2 Lessen the Learning Curve .................................................. 274

    9.1.3 Mind That Bus .................................................................... 274

9.2 API Documentation ........................................................................ 275

    9.2.1 phpDocumentor ................................................................. 275

    9.2.2 JSDoc ................................................................................. 283

9.3 Internal Developer Documentation ................................................ 288

    9.3.1 Coding Standards ................................................................ 289

    9.3.2 Programming Guides ...................................................... 293

    9.3.3 Style Guides .................................................................... 295

Chapter 10 Game Development...........................................................................297

10.1 A Different Kind of Security ...................................................... 299

    10.1.1 Validation ..................................................................... 300

    10.1.2 Server-Side Logic .......................................................... 302

10.2 Single Player ............................................................................... 304

    10.2.1 Double Buffering with Canvas ...................................... 305

10.3 “Real-Time” Multiplayer ............................................................. 310

    10.3.1 Streaming Response ...................................................... 310

    10.3.2 WHATWG event-source Element ................................ 315

    10.3.3 Predictive Animation .................................................... 317

Chapter 11 Conclusions ......................................................................................321

11.1 Remember the Users ................................................................... 322

11.2 Design for the Future .................................................................. 323

11.3 Develop for the Future................................................................ 324

Bibliography ..........................................................................................................325

Appendix A Resources ..........................................................................................329

Appendix A OpenAjax ..........................................................................................333

Conformance ......................................................................................... 334

Namespace Registration ......................................................................... 337

Event Management ................................................................................ 338

Index ......................................................................................................................341

Index

Download the Index

Introduction

Download the Introduction

Updates

Submit Errata

More Information

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020