Forum Moderators: coopster

Message Too Old, No Replies

How to push updates to your website in real time

         

andrewsmd

2:56 am on Nov 18, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm curious as to how websites such as facebook or twitter can push updates to your page as you are viewing them. I understand php and ajax, I just don't know the concept behind how they sends those updates to the browser without user interaction. I'm just looking for a general explanation here. I can figure out the code, it's the concept I'm after. Not opposed to any good resources to read too. Thanks,

tangor

4:47 am on Nov 18, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



In general there is a periodic refresh of the page, during which any new content will be displayed.

explorador

5:19 pm on Nov 19, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Updates to the page the user is viewing? Ajax combined with your server side scripting.

I just don't know the concept behind how they sends those updates to the browser without user interaction


Use javascript setinterval to solve it.

  • Set your page to load content via ajax from your server and display it, be it onload or via button-link (make it a function, so you can call it diff ways)
  • Once you have that working you can automate it setting an interval calling that function, this way the user will not need to hit refresh or to reload the page.


That's easy, just getting the data and display it. The tricky part is saving time, work and bandwith. You could set your app to only check for items-news and Ids... so you can check it against the ones you already have on your page, thus, only calling the content you don't have. This is better than getting the whole content again and again, just push it (add it) to the one you have on your page.

good luck

andrewsmd

9:18 pm on Dec 1, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I guess I was unaware they refreshed the page. I thought that they were somehow pushing data to it in real time. I have written things that refresh every so often to update data.

andrewsmd

9:18 pm on Dec 1, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I guess I was unaware they refreshed the page. I thought that they were somehow pushing data to it in real time. I have written things that refresh every so often to update data. Thanks for your insight.

penders

11:56 pm on Dec 1, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I guess I was unaware they refreshed the page.


I think it's confusing to say 'refreshed the page' here, since I believe that is what you are trying to avoid here?

As mentioned by explorador, you can use timer events - setInterval() and setTimeout() - to initiate XMLHttpRequests (AJAX) once the page has loaded rather than directly on a user triggered event.

Tommybs

8:09 am on Dec 3, 2010 (gmt 0)

10+ Year Member



I think I mentioned this in another post, but there's also the possibility of using something like a comet server with ajax push technology ( I only know of ape project, not used it myself though, I'm sure there are others) or other techniques such as long polling and utilising hidden iframes. Unfortunately finding a decent example using these is proving to be a stumbling block

chrisranjana

10:17 am on Dec 3, 2010 (gmt 0)

10+ Year Member



Yes all the above techniques are valid. To learn more about the comet

[ape-project.org...]