request to /collect is cancelled on slow connection
kandros opened this issue · 1 comments
I noticed the requests were cancelled on a slow network (video below)
The request get's cancelled if /collect doesn't return within a second, which seems a bit low or even unnecessary.
https://github.com/benvinegar/counterscale/blob/main/public/tracker.js#L151
// in case img.onload never fires, remove img after 1s & reset src attribute to cancel request
window.setTimeout(() => {
if (!img.parentNode) {
return;
}
img.src = "";
document.body.removeChild(img);
}, 1000);
Would you be open to increasing it to something like 5 seconds @benvinegar? It can be easily configured via a data-attribute in the script tag but It's a bit overkill. Or maybe remove that logic altogether?
CleanShot.2024-04-04.at.01.18.42.mp4
Oh interesting. I mean, this behavior was forked from Plausible's script (the license and copyright is maintained at the top of the file). I didn't think too much about why this was here.
I can't rationalize a great reason for why it's there, but I'm sure it was put there for a reason and it's worth trying to figure out why that is. I'd probably poke at other similar scripts to see if anyone else is using that pattern / convince myself it can be removed.