推送网站通知[关闭]

i'm building an auction site at the moment, there's some problem that i still don't have the solution... How to have push notification in website (like facebook did). i need to show on screen when a winning bid is overtaken by other bidder.

I tried with interval ajax (pull request) it took a lot of server resource.

please help.

Thanks

Interval AJAX is the worst solution. Use some real time API like PUSHER.

Example

Basically, you're wanting "Long Polling" or an "instantaneous response feature". You should take a look at long polling (push technology), understand it, then choose the right language, technologies and architecture to fit the job.

In a web/AJAX context, long polling is also known as Comet programming.


If you want to build 'something like facebook did' you're going to need a lot of research into the following and some Javascript skills. Its the only language you'll be using.

  • Node.js: A backend server that can use sockets to deliver real time updates to the browser.
  • Backbone.js: A semi structured way of building single page applications "like facebook"

I'd also include Require.js to that list which is basically used to load all the Backbone Javascript files asynchronously. It helps to keep the file structure of your application maintainable.


In closing it's good to see that you've realised the downsides of pulling data on a regular basis; as this will take it's toll on the server. Research Long Polling and you'll learn a lot of useful and interesting stuff :) Remember - choose the right tool for the job.

If you only have to support modern browsers, maybe HTML5 WebSockets could be a solution:

http://www.html5rocks.com/en/tutorials/websockets/basics/

They allow you to "listen" for data in the browser. But if you have to support older browsers, you have to go with the other proposed solutions.