javascript - document.createElement('img') v/s new Image()? which one to be appended to the DOM? -


so problem this(different discussed here: in mobile advertising, impression trackers, 2,3 or 4. since network bandwidth limited, want fire available trackers simultanenously, , not in waterfall manner(please don't ask me why).

there code have been using:

<script type="text/javascript">  var imp_1 = document.createelement("img");  imp_1.src = "tracker url 1 here";  var imp_2 = document.createelement("img");  imp_2.src = "tracker url 2 here";  var imp_3 = document.createelement("img");  imp_3.src = "tracker url 3 here";  var imp_4 = document.createelement("img");  imp_4.src = "tracker url 4 here";  </script>  

update of these 1x1 impression trackers pointing different servers, different attribution partners.

my question :

  1. is required add above creative img vars dom? practice in scenarios?

  2. would document.body.appendchild() trick?

  3. if instead used new image() in place of document.createelement() work differently here? working on putting settimeout() against each of trackers, fire them simultaneously, new image() able itself?

is required add above creative img vars dom? practice in scenarios?

you not have add image dom. but, if want visible in page, have in dom somehow adding dom how gets displayed. 1 common situation image might not added dom when precaching image (causing browser download image in cache when later needed).

would document.body.appendchild() trick?

document.body.appendchild(img) add image end of <body> section of dom. that. but, not want image in dom other code locates position elsewhere may required.

if instead used new image() in place of document.createelement() work differently here? working on putting settimeout() against each of trackers, fire them simultaneously, new image() able itself?

you can use either new image() or document.createelement("img"). either create image object same. unclear me reference settimeout() about. image tag doesn't have built in timing capability. if wanted load image specific time in future, want use settimeout() call schedule event specific time in future.

you not control whether browser requests n images simultaneously or whether gets of them , of them after first few have finished. browsers have connection limit per origin , fire many connections @ once same origin. when subsequent requests come in after limit has been reached queued until of open requests finish.


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -