Hi everyone,
My web application heavily relies on caching HTML responses at the edge to provide a faster UX. We collect a lot of performance metrics on the client side (web vitals, custom metrics, etc) and would like to add the cf-cache-status response headers as a dimension to the collected metrics. This would allow us to compare different performance metrics of cached vs uncached document responses, and calculate the business impact of having high cache hit ratio.
I think the cleanest option would be adding a server-timing response header that contains the cf-cache-status value, since this is the only document response header accessible by javascript on the client side. I considered adding a Transformation Rule to add a response header, but according to the Transformation Rules’ reference docs, the response headers and the cf-cache-control header are not available. Is this document up-to-date? I think I saw somewhere else (can’t find it now) that the cf-cache-status header was available in page transformation rules.
Another option could be adding a Worker that intercepts the response and either adds the server-timing header or adds a HTML header tag with the cache status value, but I would try to avoid this if possible.
Does anyone know if there’s another option to get access to this header?
I’m not sure why you’d need to do this instead of just handling the value of cf-cache-status directly, but yes, you can use Transform Rules to set a response header that will duplicate that value in a server-timing header.
If your origin is returning Server-Timing already, you may want to try using the concat() function so that the value of cf-cache-status is appended to the original value of the ST header.
Could you share a link? It may be a reference to transforming request headers. You can’t modify a request header with the value of a response header, though the other way around is possible.
When doing XHR/fetch API calls from web JS applications you have access to all response headers, but this is not the case for the main HTML response; the only available header is server-timing via the PerformanceServerTiming browser API.
The available fields when setting an HTTP response header value using an expression are the following:
It may be that this only refers to the “When incoming requests match…” expression. These are the fields upon which you can build the logic that will filter requests, not the fields available as part of the transformation itself. Certainly could be rewritten to make it clearer.