HttpClient Best Practices

You must Login before you can answer or comment on any questions.

What is the recommended way to make multiple httpRequests in successsion? I am trying to aggregate multiple rss feeds into one timeline, I could have anywhere from 2 to 10+ feeds that need to be looped through. Each feed could have up to 25 results.

Simply put, what is the recommended, best practices way to accomplish this? Do I create one global request object that gets called each time a feed needs to be fetched? Or do I create a local request object that gets instantiated each time a new feed is requested.

Currently, I am creating a new local request each time a feed is requested, however it is resulting in seemingly random crashing and seems prone to memory leaks.

— asked 2 years ago by Nick Ueda
3 Comments
  • are you waiting for the requests to complete before firing off a new one?

    — commented 2 years ago by Aaron Saunders

  • @aaron After reading your post here: http://bit.ly/kJTmCH I tried creating one global request object as referenced here(http://bit.ly/jGam9x), then recursively calling my import at the end of the onload event.

    — commented 2 years ago by Nick Ueda

  • @aaron other than trying to fire off a new request at the end of the onload, I am not sure how to determine if a request is complete.

    — commented 2 years ago by Nick Ueda

3 Answers

Accepted Answer

After working with nick, here is the solution I cam up with, the missing piece was to use only one instance of the httpClient instead of creating a new one each time.

full solution on gist

The number one rule in web development performance is reduce the number of http requests. What I would do is set up my own service that handles aggregating the feeds, and then connect to that for the feed. At the very least, I'd use one of those customizable feed aggregators and then fetch the content from that.

That said your xhr objects shouldn't be leaking so badly that its crashing the app... I've got a four tab app that does a http request every focus for two of the tabs and it works fine. So you probably have some workflow issues there.

— answered 2 years ago by Todd Wade
answer permalink
1 Comment
  • Setting up my own service is definitely an option. However, I want to make sure that my understanding of handling multiple httpRequests is solid.

    — commented 2 years ago by Nick Ueda

For what you are looking for, I would recommend making the requests in a multi-threaded fashion, fill a database and then fire an event to update the timeline each time a data set is updated. For my apps, I typically take the load off the device and I have written code on a server to aggregate the data and then do one call/connection from the device.

You could also use setTimeout to call them at the same time since it will act as a separate thread to my knowledge.

setTimeout(function(){  // separate thread  },100);
I would also check out the suds client. I create objects with get methods to download the data and store it to a database. You could then create a method for the object to display the list.

Your Answer

Think you can help? Login to answer this question!