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

count.js forbids caching #342

Closed
anarcat opened this issue Jul 15, 2020 · 6 comments · Fixed by #348
Closed

count.js forbids caching #342

anarcat opened this issue Jul 15, 2020 · 6 comments · Fixed by #348

Comments

@anarcat
Copy link

anarcat commented Jul 15, 2020

It seems like the count.js file, as loaded by the following "site code" blob:

 <script data-goatcounter="https://analytics.anarc.at/count" async src="//analytics.anarc.at/count.js"></script>

Never gets cached. Here, a reload of the page yields a full GET request on the resource, and the server dutifully responds with a 200 status code, with the following header:

cache-control: no-store,no-cache, max-age=43200

Shouldn't there be a way to cache (yet still run) that code when we visit a different page? I know that I can inline the script directly in the <script> tag. That saves a TCP request, but then you add 2K to all page loads...

@anarcat
Copy link
Author

anarcat commented Jul 15, 2020

a workaround, using an apache proxy, looks like:

        <Location /count.js>
                Header set cache-control max-age=43200
        </Location>

@arp242
Copy link
Owner

arp242 commented Jul 15, 2020

It does use caching, but ETag based caching/validation; so the request sends:

If-None-Match: "3f79d23f57a38541dfcb0b2eb1df56d1-ssl-df"

And it responds with 304 Not Modified:

Etag: "3f79d23f57a38541dfcb0b2eb1df56d1-ssl-df"
Cache-Control: public, max-age=0, must-revalidate

This is the default way Netlify handles things; I think their argument is that deploys and rollbacks are easier with this, which makes sense.

I can override it with the config file; maybe adding a small 30-minute cache or so might make sense, but for most purposes it's really a micro-optimisation at best.

@anarcat
Copy link
Author

anarcat commented Jul 15, 2020

This is the default way Netlify handles things; I think their argument is that deploys and rollbacks are easier with this, which makes sense.

Hmm... but this also happens with a local deployment. Maybe I screwed up my etag setup? I usually don't send those here because of the privacy implications, and it seems they don't get passed through my Apache proxy either...

How often does count.js change anyways? I was under the impression it was pretty stable and could be cached for a long time...

@arp242
Copy link
Owner

arp242 commented Jul 15, 2020

Hmm... but this also happens with a local deployment

Oh, right; I missed that 😅 I was talking about the gc.zgo.at CDN.

I need to expand the cache parameters for the static file server over here – right now it's a pretty simplistic and applies to everything.

How often does count.js change anyways? I was under the impression it was pretty stable and could be cached for a long time

Not that often, but it does change occasionally and having people use an outdated version from a week ago has the potential to cause a lot of confusion (and possibly wrong stats in case of new features). It's a pretty small file, and the overhead is really minimal even on low bandwidth/high-latency connections.

@anarcat
Copy link
Author

anarcat commented Jul 15, 2020

It's a pretty small file, and the overhead is really minimal even on low bandwidth/high-latency connections.

Sure, but I'm also optimizing for "less TCP roundtrips" so latency matters, although async should help with that... Would still be interesting to improve on that caching...

Sorry to bother you with "home server deployments" though... ;)

@arp242
Copy link
Owner

arp242 commented Jul 16, 2020

Sorry to bother you with "home server deployments" though... ;)

It's a first-class use case; and I spent quite a bit of time to ensure it works well. So yeah, it's not a "bother" :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants