Reputation: 1174
I've been looking around for options to automatically update my page with new data from the server. My data can change from every 10 minutes to possibly 1 hour, no way to predict this. Whenever this happens, the change must appear pretty quickly on the screen (no longer than 15 seconds).
So one option is just polling and sending a request every 15 seconds, but then sending requests to the server and getting empty results for over 30 minutes does sound a bit stupid.
But if I use long-polling, is it acceptable to keep a connection open for such long periods? What if there's no new data for nearly an hour? Also if I go with long-polling, I'll need to set some timeout, wouldn't I? But then it won't make sense to end the connection knowing that there might be new data on the server, and then re-initiating the connection. That'll be regular polling with longer intervals, wouldn't it?
Would appreciate if somebody could guide me to the best solution for my problem. Thanks in advance!
Upvotes: 2
Views: 417
Reputation: 23863
If you have to support older browsers, polling is your only option.
If that is the case, the HEAD
method is pretty lightweight and can just return a status indicating that things have changed.
If you can support newer browsers, you can use the method @MikeW mentioned above, or you could look at WebSockets
I found this discussion which goes into much more detail about polling.
Upvotes: 1