Mobile Web

Server-Sent Events

This feature is supported in mobile applications only.

Server-Sent Events feature is used to realize server push in a Web environment. The server push feature has evolved over time from a hidden IFrame through Ajax polling and Comet to the current implementation of server-sent events.

The Server-Sent Events API defines a simple data structure and interface, and a communication mechanism to realize the server push. In addition, it can handle the received data in the general DOM event format. However, the API repeatedly requests the data from the client to the server, so it is not a complete server push.

The repeat period of the server request is determined by the retry value of the event stream data format. If the value is not defined, the repeat period is the default value of the browser.

The main features of the Server-Sent Events API include:

  • Creating an EventSource instance

    The EventSource interface is the core object of server-sent event implementation. Creating a new EventSource instance triggers repeated server request automatically, and allows you to use the receiving data event. When creating the EventSource instance, you must use the URL of the server page sending the event stream as a parameter.

  • Receiving server push data

    After triggering the server requests, you can receive push data from the server by implementing the message event.

    The received event stream data is parsed as a MessageEvent object, to make the target data easily accessible.

Go to top