Counting website hits using Cloudflare workers
blog.aawadia.dev
Counting website hits using Cloudflare workers
1–3 of 3 posts
Re: Counting website hits using Cloudflare workers
#2Nice tutorial. One catch:
// asynchronously make the request to the counter service
// don't wait for this to finish before responding back to the client
fetch("https://api/" + counterName, requestOptions)
I would recommend wrapping this in `event.waitUntil()`, like: event.waitUntil(fetch("https://api/" + counterName, requestOptions))
Otherwise, the Workers Runtime will cancel this call as soon as the top-level response is returned. That may not be causing any trouble here because the cancellation happens too late to actually have an effect (the cancellation would manifest as the HTTP connection to the counter API being closed, but by the time it notices it has probably already finished incrementing the counter). Still, it's a good idea to be safe add add the waitUntil().Re: Counting website hits using Cloudflare workers
#3Nice tutorial. One catch: // asynchronously make the request to the counter service // don't wait for this to finish before responding back to the client fetch("https://api/" + counterName, requestOptions) I would recommend wrapping this in `event.waitUntil()`, like: event.waitUntil(fetch("https://api/" + counterName, requestOptions)) Otherwise, the Workers Runtime will cancel this call as soon as the top-level respo…
Ah, Thanks! Didn't consider/know that