Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

request to /collect is cancelled on slow connection #58

Open
kandros opened this issue Apr 3, 2024 · 1 comment
Open

request to /collect is cancelled on slow connection #58

kandros opened this issue Apr 3, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@kandros
Copy link
Contributor

kandros commented Apr 3, 2024

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
@benvinegar
Copy link
Owner

benvinegar commented Apr 4, 2024

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.

@benvinegar benvinegar added the bug Something isn't working label Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants