0

Imagine you have big application (like facebook or G+) with tons of ajax short polling.

you have sidebar with news feed (which does not update quite often), you have notifications, you have online users and etc.

Now usually what you do it make a spearate ajax requests for each of this (at least this is what I've done)

Now I want your opinion about merging this requests together and retriving them as JSON. so let separate functions handle it's own data.

What do you think, which is the right way? Sending many requests or retriving high bandwith data?


I really like to merge my requests but never seen such requests, and I have some cons: for example consider case when this ajax calls ar merged into one, and all of them had information. It's not only will be high bandwith (havy) but also will take some time to update DOM, and maybe force browser to glitch. also javascript will take longer

should I worry about this? Can you think about other scenario, why it's bed?

CBeTJlu4ok
  • 1,072
  • 4
  • 18
  • 51
  • 1
    It's easier to set cache TTLs if you have your data split into multiple requests. – Brad M Dec 23 '13 at 21:59
  • 1
    the "right way" is to use comet – markasoftware Dec 23 '13 at 22:00
  • if you dont want to use push notifications, imo merging them into one request makes for a smoother user experience, since you are limited usually to two concurrent ajax requests....for example if you had 4 separate update requests, two would be in queue from the start, and if the user invokes another separate request at that same time, it would be fifth in line... – A.O. Dec 23 '13 at 22:04
  • it's a question of architecture more than anything, Having multiple ajax requests merged into one is commonly done for a dashboard type systems. One pattern that's useful is futures/promises, which lets you keep the main logic concentrated instead of callback hell. There are frameworks to help you here's a blog post about futures/promises http://davidshariff.com/blog/futures-and-promises-in-javascript/ – Piotr Kaluza Dec 23 '13 at 22:05

0 Answers0