Why should I reuse XmlHttpRequest objects?
Posted
by Xavi
on Stack Overflow
See other posts from Stack Overflow
or by Xavi
Published on 2010-04-21T06:24:51Z
Indexed on
2010/04/21
7:13 UTC
Read the original article
Hit count: 281
From what I understand, it's a best practice to reuse XmlHttpRequest objects whenever possible. Unfortunately, I'm having a hard time understanding why. It seems like trying to reuse XHR objects can increase code complexity, introduce possible browser incompatibilities, and lead to other subtle bugs.
After researching this question for a while, I did come up with a list of possible explanations:
- Fewer objects created means less garbage collecting
- Reusing XHR objects reduces the chance of memory leaks
- The overhead of creating a new XHR object is high
- The browser is able to perform some sort of network optimization under hood
But I'm not sure if any of these reasons are actually valid.
Any light you can shed on this question would be much appreciated.
© Stack Overflow or respective owner