1

I'm building a groceries application that allows for syncing with other members in your family who are part of a 'family' group, and when one of them update the grocery list on their devices, it will update automatically on other devices. I can do pretty much everything, but the automatically bit.

I've got .load working with setInterval, but it only functions (stable) when the interval is set to a few minutes, because making the call once every few seconds is a bit excessive on the server :\

I believe the way to do this is with long polling, which I still have no idea how to do, but could anyone suggest how I could do this efficiently? In a way that might not lag like crazy on mobile too? Because I do intend to push this over to mobile.

Or if it means less load on the server, would anyone know how to do it like Twitter does '1 new Tweet' when new content gets detected?

Any help greatly appreciated! :)

Cheers, Karan

Karan
  • 267
  • 3
  • 8
  • http://stackoverflow.com/questions/4743536/push-style-notifications-simliar-to-facebook-with-rails-and-jquery and http://trihoprojects.com/2011/05/push-technology/ will help you solve your query. – Rohan Nov 11 '11 at 08:54

1 Answers1

0

If you're frequent polling is too excessive on the server then you need to revise the logic on the server. Rather than hit the database during every single request you should have something where the server caches a status in a session variable or something similar. Then when a user makes a change, invalidate the cache, so that after that one of those poll requests from the Javascript actually incurs the full hit to the server.

Another thing I would say is be careful on the long running response paradigm. It's a handful and practically everything I've seen in the wild has used frequent polling instead. Take a peak at this old thread.

Comet VS Ajax polling

If you are still interested in the long running response have a look at Comet.

Community
  • 1
  • 1
quickshiftin
  • 66,362
  • 10
  • 68
  • 89