I have a simple web app which lists a private group of people and the last message they posted.
I’m currently just polling by using Ajax to hit a php script every 30 seconds, which gets all people and latest messages then returns as JSON. I parse that and update the DOM.
Not very efficient since most of the time, nothing has changed but it still gets all data each 30 seconds.
-
Is there anything basic I can do, just with the code to improve this?
-
Should I use something like pusher.com?
There are a lot of tutorials out there on implementing long polling but I’d like to keep this simple as possible.
when you use request http every 30 second it’s possible many resource will be use, if there are 1000 users and more i think it’s not good for web server,
i have suggestion using Nodejs , node js is javascript server a platform built on Chrome’s JavaScript runtime for easily building fast,and support longpolling ,and non block request.
with nodejs you can build your webserver that can be handle many users and for realtime application.
there are many framework can be implement with node js
and this is simple tutorial if you want to try that..
http://martinsikora.com/nodejs-and-websocket-simple-chat-tutorial