Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

<img src> w/ timeout?

I have some tracking pixels on our site, that I'd like to protect against them impacting our user experience if their servers are down or slow. What's the easiest way to specify a maximum time the browser should attempt to load a given img - i.e. try for 100ms and then give up? (I'd rather not track a given customer than have a server hang on the third-party server impact our site).

like image 764
Michael Reston Avatar asked May 01 '12 15:05

Michael Reston


1 Answers

You could insert the <img> with JavaScript and use setTimeout() to remove it after 100ms.

Example with jQuery:

var tracker = $("<img>", { src: trackingUrl }).appendTo(document.body);
setTimeout(function() { tracker.remove(); }, 100);
like image 187
Electro Avatar answered Sep 30 '22 18:09

Electro