Advanced Ajax: Architecture and Best Practices
暫譯: 進階 Ajax:架構與最佳實踐

Shawn M. Lauriat

  • 出版商: Prentice Hall
  • 出版日期: 2007-10-25
  • 定價: $1,485
  • 售價: 6.0$891
  • 語言: 英文
  • 頁數: 384
  • 裝訂: Paperback
  • ISBN: 0131350641
  • ISBN-13: 9780131350649
  • 相關分類: Ajax
  • 立即出貨(限量) (庫存=1)

買這商品的人也買了...

商品描述

Description

“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

 

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

商品描述(中文翻譯)

**描述**

“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, Zend Technologies 共同創辦人及共同首席技術官

**關鍵任務 Ajax:最大化可擴展性、性能、安全性、可靠性和可維護性**

**《進階 Ajax:架構與最佳實踐》** 是一本關於使用 Ajax 建立業務關鍵、可生產的 Web 應用程式的權威指南。Shawn M. Lauriat 系統性地解決了與 Ajax 相關的設計、架構和開發問題,提供了其他書籍中無法找到的經驗模式和穩健的程式碼範例。您將找到針對企業 Ajax 開發人員面臨的全範圍問題的最佳實踐:可擴展性、性能、安全性、可靠性、靈活性、可維護性和可重用性。

針對經驗豐富的 Web 開發人員撰寫,Lauriart 提供了新穎的想法和優雅的解決方案:豐富的技術內容,以卓越的清晰度呈現。在他深入探討的眾多主題中,包括:乾淨地實現 JavaScript 自定義事件以減少耦合並增強靈活性;克服 Ajax 的傳統可及性限制;通過壓縮和其他技術減少網路延遲;以及更多內容。涵蓋的主題包括:

- 計劃簡單、清晰和直觀的 Ajax 介面
- 為客戶端 JavaScript 創建可擴展、可維護的架構
- 使用最新工具來分析、驗證和除錯客戶端程式碼
- 為安全性和功能架構伺服器端,同時限制加載的數據、物件和動作僅限於當前請求
- 防範最廣泛和最重要的 Ajax 安全風險
- 優化 Ajax 應用程式的每個組件,從伺服器端腳本到數據庫交互
- 介紹尖端 Ajax:遊戲開發、使用 canvas 的 Ajax 和企業應用程式的 Ajax

**目錄**

致謝 ......................................................................................................... xiii
關於作者 ............................................................................................................xv
導言 ............................................................................................... 1
0.1 Ajax,這個縮寫 .............................................................................. 2
0.1.1 非同步.......................................................................... 3
0.1.2 JavaScript ................................................................................ 3
0.1.3 XML ....................................................................................... 4
0.2 本書的意圖 .............................................................................. 5
0.3 本書的前提條件 ................................................................. 8
第一章 可用性 ................................................................................................11
1.1 介面與展示 ......................................................................... 12
1.1.1 實施 .................................................................... 14
1.2 使用者期望 ............................................................................. 16
1.3 指標和其他形式的使用者反饋 .................................. 17
1.3.1 加載指示器 ........................................................................ 17
1.3.2 進度指示器 ................................................................ 20
1.3.3 讓使用者保持在循環中 ................................................ 22
1.4 語意標記 ............................................................................. 30
1.4.1 更具可及性 ..................................................................... 30
1.4.2 更易於使用 ......................................................................... 32
1.4.3 更易於維護 ......................................................................... 33
1.4.4 更易於解析 ......................................................................... 34
1.5 CSS 和 JavaScript 的共同點 .................................... 37
第二章 可及性 ..........................................................................................43
2.1 WCAG 和第 508 節 ................................................................. 44
2.1.1 WCAG ................................................................................ 45
2.1.2 第 508 節 ........................................................................... 51
2.2 螢幕閱讀器可以處理 Ajax .................................................. 53
2.2.1 內容替換 ........................................................................... 54
2.2.2 表單驗證 ........................................................................... 55
2.3 不干擾的 Ajax .............................................................................. 56
2.4 設計時考慮可及性 ................................................................. 58
2.4.1 高對比度設計 ................................................................. 59
2.4.2 可縮放介面 ....................................................................... 60
2.4.3 易於定位的控制項 .......................................................... 62
2.5 WAI-ARIA .................................................................................. 63
第三章 客戶端應用程式架構 ..........................................................67
3.1 物件和事件觸發 .................................................................... 68
3.1.1 原生物件事件處理 .................................................. 70
3.1.2 JavaScript 物件 ................................................................. 71
3.2 模型-視圖-控制器設計模式 ........................................... 87
3.2.1 模型 .................................................................................... 88
3.2.2 視圖 .................................................................................... 92
3.2.3 控制器 ................................................................................ 101
3.3 事件驅動的應用程式開發 ................................................. 104
3.3.1 架構的優勢 ................................................................. 104
第四章 除錯客戶端程式碼 ..............................................................107
4.1 驗證、驗證、驗證 ................................................................. 108
4.1.1 標記驗證器 ...................................................................... 109
4.1.2 CSS 驗證器 ...................................................................... 110
4.1.3 語意提取器 ...................................................................... 111
4.2 瀏覽器工具和插件 .............................................................. 111
4.2.1 控制台 ............................................................................... 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 性能分析 ............................................................ 126
4.3.1 辨識瓶頸 ........................................................................... 128
4.4 單元測試 .................................................................................. 132
4.4.1 斷言 .................................................................................... 134
4.4.2 測試設置 .........