I want to embed a fire-and-forget request for img src in JavaScript

I am trying to implement fire-and-forget on a call to img src = ... from a web page and am looking for the most reliable method. Why?

Most web tracking systems, such as Omniture or Coremetrics, have a request for img src, which also transfers all the data for the tracking system for recording. Like any other image request, the page tries to wait for an answer, which may slow down the page loading.

What I'm trying to do is to implement a tracking system in which the response time of a web page is a much higher priority than whether the request was really successful and therefore waiting for a response is completely unnecessary under all conditions, including ...

  • The server has received the request and can readily respond (HTTP 200 response code)
  • The server has received the request, but is bogged down, and can readily respond with a 500 error response code.
  • Server is down at all
  • Server not found due to DNS failures
  • The request arrives at the server, but it is so bogged down that it takes noticeable time to respond.

I already explored the use of the XMLHttpResponse object and the asynchronous request, which can calmly fail, but you quickly run the same origin policy and browser code. I believe that a simple jane img request is still the best request mechanism, but I am trying to develop a better fire-and-forget implementation with the least amount of code. I still know that I can ...

OnError = "this.parentNode.removeChild (this)" OnLoad = "this.parentNode.removeChild (this)"

1 4, . 5, , - .

, this.src.readyState == "", , , StackOverflow .

- ?

+3
6

img ?

+2

, . Google , - , eVisitAnalyst .

brucey , , , .js , .

+1

My PoV: , . WebTrends/Omniture Coremetrics, , ( , ) . - , , ( IP- - - Omniture/Coremetrics , , , , ..). - , 1x1 , , ( google urchins , , ). , , (jQuery - Document.ready?), <img src="vendor url"/> html dom.Even, , , .

0

, img .

: 1) , 2) img. $(document).ready() JQuery 1) DOM 2) ( JQuery).

, , (, JQuery, , , , ) , , .

EDIT: typo

0

POST , iframe ( ).

, , iframe .

:

<form target="targetIfr" action="http://domain.com/" method="post">
    <input name="data" type="text" value="hello" />
</form>
<iframe name="targetIfr"></iframe>

:

frm.submit();
ifr.parentNode.removeChild(ifr);
0

, , , - . CoreMetrics Adobe , dom, , JS, , outImage = new Image(); DOM , . 1x1 MIME-.

JS, , .

0

Source: https://habr.com/ru/post/1730413/


All Articles