Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript AJAX Basics (retiring) AJAX Concepts A Simple AJAX Example

How does XHR object affects the performance? Is it a very large and heavy API? Thanks

How does XHR object affects the performance? Is it a very large and heavy API? Thanks

3 Answers

Iago Wandalsen Prates
Iago Wandalsen Prates
21,699 Points

Are you talking client-side or server side? On your client side, its going to cost your user processing the data it receives. Ajax functions are asynchronous, so the program make the call, keep doing your stuff, and when it gets an answer, it deals with the data it received. On server side it gets a little more complicated, it depends wether or not your server is asynchronous, but that should only matter if your server get a BIG traffic.

Ajax is not an API, its just a part of Javascript.

Thank you very much for your answer!

Chris Shaw
Chris Shaw
26,676 Points

Hi Hernán,

An XHR request in general won't affect your sites performance however it really depends on what you need to do with it as if you're making lots of requests to a single source that has a decent amount of data that can use up more memory of the users browser potentially slowing down the site in the process or even locking up the browser.

If you can provide an example of what you need to use it for it will help to determine ways to optimize the request and possibly even use real time caching.

I don't really have an example, it's a question that somebody did to me the other day and i didn't find any answer.

Real time caching is something you can do with javascript? Thanks.

Chris Shaw
Chris Shaw
26,676 Points

Indeed, the two most common options you have for caching are.

  1. Direct caching via the ajax request, all modern browsers support this and from memory IE8 has partial support
  2. Store data within your own custom arrays/objects and only request new data when requested otherwise use the cached data

Thanks both of you :O)