Smart Polling

The data on the server is checked every 7 seconds for an update. The client Ajax request includes an If-Last-Modified header to limit the load on the server; also allowing the client code to not have to update the UI if the data has not changed.

Below, sample JSON data from the server is displayed. To simulate an update to this data on the server, a button is provided which will send an Ajax POST request to the server, updating the data. The data is a simple JSON structure containing a label element and the current time on the server when the file was written. Sending a request to update the data will change this timestamp written in the file.

The periodic polling task will continue checking for updates to the data as long as the window is in focus. If the window goes out of focus (blur), the polling will stop. If the window regains focus, an immediate Ajax request is sent to check for any changes, and polling resumes.