天天看點

Ajax Patterns 讀書筆記 --3

程式設計模式 (25)

Programming Patterns (25) Web Services

  • RESTful Service Expose web services according to RESTful principles.
  • RPC Service(遠端程式調用) Expose web services as Remote Procedural Calls (RPCs).
  • HTML Response(直接生成HTML代碼片斷傳回) Have the server generate HTML snippets to be displayed in the browser.
  • Semantic Response(以特定語義的資料封裝方式傳回) Have the server respond with abstract, semantic, data.
  • Plain-Text Message (Text格式傳遞)Pass simple messages between server and browser in plain-text format.
  • XML Message (XML格式傳遞)Pass messages between server and browser in XML format.
  • JSON Message Pass messages between server and browser in Javascript Object Notation (JSON) format.

浏覽器 - 伺服器對話

Browser-Server Dialogue

  • Call Tracking Accommodate busy user behaviour by allocating a new XMLHtpRequest object for each request. See Richard Schwartz's blog entry.Note: Pending some rewrite to take into account request-locking etc.
  • Distributed Events Keep objects synchronised with an event mechanism.
  • On-Demand Javascript (立即響應JS)Download Javascript as and when required, instead of downloading it all on page load.

DOM Population

  • XML Data Island(XML資料島) Retain XML responses as "XML Data Islands", nodes within the HTML DOM.
  • Browser-Side XSLT(浏覽器端XSLT) Apply XSLT to convert XML Messages into XHTML.
  • Browser-Side Templating(浏覽器端模闆) Produce browser-side templates and call on a suitable browser-side framework to render them as HTML.

性能優化

Performance Optimisation

  • Fat Client (建立富用戶端)Create a rich, browser-based, client by peforming remote calls only when there is no way to achieve the same effect in the browser.
  • Browser-Side Cache (浏覽器端緩存)Maintain a local cache of information.
  • Guesstimate(估計值替代伺服器端的真實資料讀取) Instead of grabbing real data from the server, make a guesstimate that's good enough for most user's needs. ITunes Download Counter, GMail Storage Counter.
  • Submission Throttling(送出調節) Instead of submitting upon each Javascript event, retain the data in a local buffer and upload it periodically.
  • Explicit Submission(顯示送出) Instead of submitting upon each Javascript event, require the user to explicitly request it, e.g. submit upon clicking a button.
  • Multi-Stage Download (頁面分級下載下傳)Quickly download the page structure with a standard request, then populate it with further requests.
  • Predictive Fetch(資料預取) Anticipate likely user actions and pre-load the required data.

擴充

Extension

  • Cross-Domain Proxy (跨域代理)Allow the browser to communicate with other domains by server-based mediation.
  • Richer Plugin(更“富”的插件) Make your application "more Ajax than Ajax" with a Richer Plugin.

代碼産生與重用

Code Generation and Reuse

  • Ajax Stub (樁)Use an "Ajax Stub" framework which allows browser scripts to directly invoke server-side operations, without having to worry about the details of XMLHttpRequest and HTTP transfer.
  • Server-Side Code Generation(服務端的代碼生成) Automatically generate HTML and Javascript from server-side code.
  • Cross-Browser Component (跨浏覽器元件)Create cross-browser components, allowing programmers to reuse them without regard for browser compatibility.

待續 --3

繼續閱讀