Skip to content

Instantly share code, notes, and snippets.

@kerryChen95
Created March 30, 2013 06:24
Show Gist options
  • Save kerryChen95/5275614 to your computer and use it in GitHub Desktop.
Save kerryChen95/5275614 to your computer and use it in GitHub Desktop.
function sendLog (urlWithLog) {
var img = new Image(), no, caches;
if (sendLog.count >= Number.MAX_VALUE) sendLog.count = 0;
no = 'no' + sendLog.count++;
caches = sendLog.caches;
// hold on reference, otherwise image object may be GCed and abort request that has not been send
caches[no] = img;
// delete reference
img.onload = img.onerror = img.onabort = function () {
delete caches[no];
};
img.src = urlWithLog;
}
sendLog.caches = {};
sendLog.count = 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment