The web application receives an HTTP request from a user browser. It contains session information so that (for example) a basket or an online game state between these requests can be saved.
The user usually leaves the browser session active while going for lunch, home for a day, or leaving for a two-week vacation. Consequently, sessions usually have some inactivity timeout, otherwise you get a lot of server resources that are used for users who are not coming back soon.
The heartbeat template described here uses Ajax (asynch) calls to tell the server that the user is still here. This can be useful because rich Internet applications often allow you to work quite a bit locally before new requests are sent to the server - therefore, there is a risk of disconnecting sessions when the user is happy to use the application.
Implementation must be reasonable. For example, if you just have to send an ajax call to the server every thirty seconds, saying "Yes, still here," which will continue until the user has a two-week vacation. Thus, instead of this, the pulse will only be sent when the user is actively using the application.
It might be wise to “correct” useful information in requests and responses to the pulse, for example, by sending to the server automatic data storage or retrieving updated server information or “news”.
source share