Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've been having a strange problem with externally linked Javascript libraries hanging my load balancer server running HAProxy. I recently integrated the Quantcast monitoring script, and it worked for about 12 hours, and the next morning I experienced a huge amount of network connections hanging as shown in the graph below. All of the webservers behind my load balancer were completely overloaded with connections as well. I removed Quantcast's script and the problem disappeared.

I've had this problem with some other analytics packages, but have never had this issue with Google Analytics or Adsense (both external libraries). Has anyone ever experienced this or have suggestions on how to avoid it happening?

Netstat Graph

share|improve this question

Are you sure it's caused by javascript?

Where did you paste the quantcast tag? Try it in the end of the page, just above , so it doesn't delay loading of other resources (img, css, etc).

Browsers do "hang" if they have to wait for javascript, but that's only because it has to pause the rendering thread to wait for document.write's in the script. It can't keep the tcp connection to port 80 open, except when you have a resource loading issue.

The graph looks more like a out of memory issue, if you run mpm-prefork, make sure MaxClients isn't set too high or you'll run into swap, leading to lots of established connections but nothing being served. Also, check http keepalive settings.

share|improve this answer
Yeah - I put this at the end of the page. I've had similar issues with facebook, chartbeat, and other external javascript includes. I haven't had any issues with Yahoo and Google. – Aldie Aug 31 '09 at 10:06

We generally cache external javascripts locally. that way you dont have to rely on a third party serving the JS correctly. of course, this might not be an option depending on what the js is doing or if its built dynamically. But you can, for example, host google analytic's js locally.

You can gain some additional advantages to doing this, such as

  1. Gzip - some external js files wont be gzipped
  2. Cache headers - you can set your cache headers to never expire (handling updates with a file name change)
  3. More control - of course the big guys generally arent going to introduce a breaking change, but having externally linked javascript can be risky.
share|improve this answer

Using the window.onload event, you can append external Javascript (with simple document.write or DOM construction) only when the page is fully loaded (and the connection closed).

share|improve this answer

Try deferring the running of the script with the defer attribute:

<script src="script.js" type="text/javascript" defer="defer"></script>

It tells the browser not to even think about the script until after the page has loaded. If there are no document.write's in the script it may be okay deferred.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.