Seng Keat Teh, Julien Wetterwald
- 1 Introduction
- 2 What is interesting about Gmail's pagination feature?
- 3 Overall structure of Gmail's Pagination interaction
- 5 Client and Server-side Interaction in Gmail's Pagination
- 6 Data fetching and updates in Gmail's Pagination
- 7 Questions
Introduction[edit | edit source]
In this project, we analyze specifically how the browser communicates with the Gmail service when paginating through the inbox. Pagination in Gmail's dynamic AJAX web application happens much faster than pagination in traditional, non-AJAX, non-dynamic web applications such as old-style Hotmail. Traditional pagination is usually implemented as links between documents generated by the server. Each time the user navigates between pages, a complete HTML document is generated and sent to the browser. This approach has mainly two disadvantages:
- Each time a new page is loaded, the whole UI is sent to the browser. Because most of the UI is identical to the previous page, superfluous information is transfered between the server and the browser.
- Unless the application relies on cookies, there is no way to maintain state and cache data objects in the browser each time the user leaves a page. It is thus difficult to do any kind of smart prefetching, such as prefetching the content of the e-mails on the current page.
However, pagination in traditional non-dynamic web apps has the following advantages over dynamic AJAX-based web applications:
- Allows browser's in-built progress bar to depict genuine information about the progress of loading the HTML page showing the next set of results. This gives a user a more accurate expectation of how long more it would take to load and render the next set of results as the user paginates. A non-informative placeholder spinner is instead used in most AJAX web applications while waiting for the server response containing the requested data.
- Allows browser history while paginating as the next set of results are loaded in a completely new HTML page. A user can get back to the previous set of results by merely clicking the browser's Back button. The same cannot be done with AJAX-based web apps as they usually modify the DOM structure of the current webpage to render additional new information. Thus, the browser records no history.
Gmail's dynamic pagination addresses both weaknesses with traditional non-AJAX-based web apps. As a dynamic AJAX-based web app, Gmail modifies the same HTML page when displaying the next set of data items as the user paginates, and caches and prefetch email messages to speed up pagination. At the same time, Gmail's pagination also has the advantages of traditional non-dynamic web apps. It allows the browser's in-built progress bar to depict genuine progress information as Gmail fetches the next set of emails, and also supports browser history when a user paginates.
What is interesting about Gmail's pagination feature?[edit | edit source]
- Gmail takes advantage of the browser's built-in progress bar to depict genuine progress information while fetching the next set of emails instead of the usual placeholder spinner used in most AJAX web applications
- Support of browser history in pagination of emails
- How a user's e-mail data is loaded and stored on the client-side as the user paginates through his/her e-mail messages
- Prefetching and caching decisions made for fetching the next set of email messages when paginating in the user's inbox
- The use of "chunked transfer encoding" to allow Comet-style updates from server to client about new e-mail messages received (in the /bind URL)
Overall structure of Gmail's Pagination interaction[edit | edit source]
- User clicks on one of the pagination links "« Newest", "‹ Newer", "Older ›" and "Oldest »" to navigate among his/her collection of emails
- Gmail initiates a GET HTTP request to fetch the email titles, email message snippet previews and email IDs of the next requested set of emails
- The browser's in-built progress bar depicts the progress to completion of this GET HTTP request
- Gmail modifies the same HTML page to remove the previous set of email results displayed, and loads the email titles and email message snippet previews (the result of the successful GET HTTP request) of the next requested set of emails
- While user views the rendered email titles and snippet previews, in the background, Gmail initiates a series of XHR calls using POST HTTP requests to fetch the full contents of the user's e-mail messages for the currently viewed set of emails
- Processes the event handling when clicking on the pagination links "« Newest", "‹ Newer", "Older ›" and "Oldest »".
- Used to initiate various asynchronous GET and POST HTTP requests to fetch a requested set of e-mail messages. (Note: Loading a new page in a normal browser window or in an IFrame is initiating a GET request. )
- Supports the 2-step AJAX e-mail data fetching in Gmail as the user paginates through e-mails:
- 1st step is a GET HTTP request to get only email titles, email message snippet previews and email IDs triggered by changing the target of a hidden IFrame.
- 2nd step is a series of XMLHttpRequest (XHR) calls that results in a series of POST HTTP requests fetching full contents of user's e-mail messages. Full e-mail messages are requested in batches of 10 emails instead of the whole set of results all at once.
- Helps interpret the results returned by the series of GET and POST HTTP requests involved in supporting the 2-step AJAX email data fetching in Gmail:
- Helps facilitate caching of e-mail messages previously fetched so that paginating and viewing such emails do not require any further interaction with the Gmail service.
Client and Server-side Interaction in Gmail's Pagination[edit | edit source]
We will explain how the interesting features of Gmail's pagination interaction work together such as Gmail's use of the browser's in-built progress bar, browser history support for pagination, and its 2-step AJAX e-mail data fetching, as the user paginates through e-mails. We will point out which parts of the interaction are on the client-side/browser and which requires interaction with the server/cloud.
- 1. Gmail's web app layout is made up of four IFrames (HTML elements that allow the embedding of other HTML pages in a HTML page), labelled respectively as:
- hist_frame: A hidden IFrame that is probably utilized to give browser history support to Gmail
- sound_frame: A hidden IFrame where a flash object is loaded to provide sounds for Gmail's chat feature
- canvas_frame: The main IFrame that is seen by the user and where all the graphical rendering of the Gmail web app occurs
- 2. When the user clicks on one of the pagination links "« Newest", "‹ Newer", "Older ›" and "Oldest »" to navigate among his/her collection of emails, Gmail initiates a GET HTTP request that fetches the email titles, email message snippet previews and email IDs of the requested next set of emails from the Gmail server (Server Interaction). This is also the 1st step in the 2-step AJAX email data fetching that Gmail does.
- 3. The event handling when a user clicks on a pagination link and the initiation of the GET HTTP request (Client Interaction) is handled by Gmail's JS code residing in the browser.
- 4. This GET HTTP request is initiated by Gmail's JS code by changing the target of a hidden IFrame, which we suspect is probably Gmail's hist_frame. This hidden IFrame then attempts to load and render the HTML page that is the response of the GET HTTP request. (Client Interaction)
- How this enables Gmail Pagination's support of Browser History
- The browser treats any IFrame element, hidden or not, like a browser window. Whenever the target of an IFrame element (the address of the website currently displayed in the IFrame) changes, the browser recognizes this as a change in browser history. The browser effectively records a snapshot of the DOM state of the webpage before its embedded IFrame element had its target changed.
- By loading the result of the pagination's GET request in a hidden IFrame, this effectively gets the browser to record the DOM state of the Gmail app before paginating
- How this enables Gmail Pagination's use of the browser's Progress Bar
- Most AJAX applications uses a placeholder "spinning wheel" to inform the user that some asynchronous operation is in progress. It works well for small and quick operations but is not adequate when performing large operations or computations whose responses might be delayed. It does not provide the user with an expectation or estimate when such a computation would be done.
- Fortunately, the web app programming technique termed as the IFrame transport mechanism provides exactly what's needed. Whenever the browser is loading a page inside an IFrame (hidden or not), the browser's in-built progress bar also depicts the loading progress just as it would when loading a new webpage in a normal browser window.
- The idea of the IFrame transport is to initiate the GET request by changing the target of a hidden IFrame to load the response of the request. This response contains email titles and IDs that will later be rendered to the user.
- As the hidden IFrame loads the response of the GET request, users can then notice the progress bar depicting the progress of Gmail in retrieving the email titles and IDs of the next requested set of emails.
- 6. As the 1st step in the 2-step AJAX email data fetching completes (the GET request successfully obtains the email titles, preview snippets and email IDs from the Gmail server, and these information is displayed to the user), Gmail initiates a series of XHR calls (in the form of POST HTTP requests) to the Gmail server to fetch the full content of the email messages whose titles are currently displayed to the user. (Server Interaction)
- 7. Each successful response of the XHR POST HTTP request contains a JSON formatted data structure that holds the full email contents for 10 email messages.
- 8. Thus, if a user configures his/her Gmail to display 50 emails at a time, then 5 XHR POST HTTP requests are made in the background (while the user is viewing the titles of the emails) to fetch the full content of these 50 emails.
- 9. The Gmail JS code inserts the email content obtained from successful POST HTTP requests into the DOM structure of the Gmail webpage. (Client Interaction)
- 10. When the user clicks on the title of an email to view its full content, the result is often immediate with no visible delay as the email content was previously fetched in the background.
- 11. This series of XHR POST HTTP requests by Gmail is the 2nd step in the 2-step AJAX email data fetching by Gmail.
Data fetching and updates in Gmail's Pagination[edit | edit source]
All the data required while paginating is fetched with the two following calls:
- GET /mail
- Parameters: pagination properties (e.g. start, number of e-mails)
- Response: ID, subject and preview of the e-mails in the specified range; some other data such as the labels
- Triggered by: changing the target of a hidden IFrame
- POST /mail
- Parameters: list of 10 e-mail IDs, previously returned by GET /mail
- Response: content of the specified e-mails
- Triggered by: XHR
Gmail service's response to asynchronous RPCs contains the minimal set of data objects required to update the UI. Consequently, the granularity of updates is finer than in traditional web applications, where each action requires a full reload of the document.
Despite not being used by the pagination per see, updates such as a new e-mail arriving in the inbox are pushed by the server on an open Comet-style connection at this URL:
- POST /bind
- Response: array of operations to perform (one of the operations is "noop"), chunked-encoded to avoid closing the connection after each "push"
- Triggered by: XHR
Techniques for hiding latency in Gmail's Pagination[edit | edit source]
- When paginating, e-mail titles and IDs are fetched first and thus displayed as quickly as possible to the user.
- The full content of e-mail messages is then prefetched in batches of 10s. Consequently, clicking on an e-mail subject to read its content doesn't require to talk to the server and can thus be done without any latency. Some RPCs are still triggered but only to return secondary data such as advertisements.
Questions[edit | edit source]
Are there things about the facilities of the Web that made Gmail's Pagination either easy or hard?
- The ability to use CSS to make span elements look like hyperlinks is useful to provide a usual "look and feel" to the controls in the UI.
Did Gmail's Pagination have to contort itself to get around problems with the Web?
- To get around the stateless nature of the Web, Gmail pushes the UI logic to the browser. Because a single document is used, keeping data objects in memory is easier. But using a single document introduces other problems, some of them being solved by Gmail's use of a hidden IFrame. Manipulating an IFrame can:
- trick the browser in providing some progress feedback on pending RPCs to the user.
- add "fake" events in the browser's history.
Are there improvements to the Web that would have made Gmail's Pagination easier to implement, or that would have allowed a more powerful interaction?
- Interestingly, Google is working on providing a solution to these three problems with:
- Gears: let web applications interact naturally with user's desktop by providing a local, off-line data store.
Are the techniques used in Gmail's Pagination relevant for a broader class of interactions?
- Yes, Gmail's pagination techniques can be very useful for any rich web application that needs to display a long list of data items that requires some method of pagination/navigation such as for a search catalog or an online database
- It is interesting to remember that Gmail doesn't use AJAX for eye candy effects or unpractical animations. They use it solely to smartly prefetch data to improve responsiveness and to reduce as much as possible the size of data being transfered from the client to the server.