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 that by trying to reuse XHR objects you increase your code complexity and you introduce possible browser incompatibilities. So why do so many people recommend it?
After some research, I was able to come up with this list of possible explanations:
- Fewer objects created means less garbage collection
- 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 still a bit skeptical. Are any of these reasons actually valid? If not, what is a valid reason?