Preview
The technique discussed in this article is introduced in version 32.3.0, which ships with TX Text Control 32.0 SP3.
Long polling is a technique used to push updates from the server to the client. This will allow the server to push out updates to the client as soon as new data is available. This technique is useful when the server sends new data to the client irregularly.
The server keeps the connection open and returns a stream that can be consumed by the client using JavaScript.
Unlike our Document Editor, which uses WebSockets for a consistent, very long connection, we decided to use this technique for loading documents into the Document Viewer. The huge advantage of this asynchronous loading process is that all pages are streamed to the viewer as they are generated by the server and are available for consumption. This means that while the server is still processing the remaining pages, the user can begin reading and annotating the document. This is a significant advantage over the traditional method of loading the entire document at once, which can take a long time for large documents.
Traditional Loading
The following screen video shows the Document Viewer loading a 196-page document using the old method. The document is loaded in one go, and the user must wait until the entire document is loaded before they can begin reading it. The video shows only the initial loading sequence to illustrate that the viewer is not usable until it is fully loaded.
Long-Polling Loading
Now, let's see the same document being loaded using the new long-polling method. The document is loaded in chunks, and the user can start reading it as soon as the first pages are available.
Network Traffic
In the Google Chrome F12 Developer Tools, you can see the network traffic of the long-polling requests. The server sends the pages as they are generated, and the client consumes them immediately. Pay attention to the request type which is fetch instead of XHR.
Conclusion
Using long-polling for loading documents into the Document Viewer is a significant improvement in terms of user experience. The user can start reading and annotating the document as soon as the first pages are available. This asynchronous loading process is a great addition to the Document Viewer and will be available in the next service pack.