My team had an idea about using Cloudflare Workers to help monitor our site performance. The idea is to capture various metrics related to page load time as the user experiences it, including an approximation of time to first paint and time to interactive. We would start the measurement at the time Cloudflare receives the request, and then use some JS code (which we can add to our pages on our end) to capture the remaining time to first-paint and time-to-interactive (both for CF cache hits and misses). Obviously this wouldn’t be a complete end-to-end test since there’s still the time it takes for the request to reach CF servers, but hopefully that’s generally pretty minimal, and it seems like relative comparisons of the metrics recorded with this solution would still provide valuable insights.
I’m rather new to performance testing and monitoring, so first of all I just wanted to ask: does this sound like a good use case for CF workers? Has anyone else done something like this?
I realize that CF already tracks some performance stats like origin response time, but starting the measurement in a CF worker and sending the data in the same way we’ll do it from the browser (e.g. with Google Tag Manager, or we might be calling some other endpoint that would talk to Prometheus), seemed like it would be simpler than combining stats from multiple sources. I was thinking that this would also give a more accurate calculation of the amount of time elapsed from the time the request is received by CF to the first paint in the browser…if we go with a custom API monitoring endpoint, we could rely on it to calculate the time difference between the two requests it would receive for a given page (the first from the CF worker and the second from the browser). Does this sound like a good plan to any veteran performance experts here?