<img src> w / timeout?

I have some tracking pixels on our site that I would like to protect against by acting on our user interface if their servers are slow or slow. What is the easiest way to specify the maximum time at which the browser should try to load a given img - i.e. Try for 100 ms and then refuse? (I would prefer not to track a specific client, than the server freezes on a third-party server, affect our site).

+7
source share
4 answers

You can insert <img> using JavaScript and use setTimeout() to remove it after 100ms.

JQuery example:

 var tracker = $("<img>", { src: trackingUrl }).appendTo(document.body); setTimeout(function() { tracker.remove(); }, 100); 
+3
source

You must download them when the document is ready. or on the last line (in html). in this way - it will not harm the user. the ready document can also be used with jQuery.

but you can use window.load.

as a rule (not always) - all scripts should be at the end of the page.

if you want to TURN OFF KILL time:

create img tag.

attach the load event to img (this function will set the flag: loaded = 1;)

install src.

with setTimeout The function you are about to kill img.

as?

if after X MS == 0 is loaded, then kill.

like this: every load event (from IMg) sets a flag (loaded = 1).

your timeout function doesn't care about anything !!! after x MS it is going to kill img - only if loaded == 0.

+2
source

You will need to use javascript for this, there is nothing native HTML / HTTP that will do this on the page. Google for "HTML IMG timeout."

0
source

You can invoke the server process in the IMG tag. Let it worry about how to unload the load.

-one
source

All Articles