Philip Walton
Philip Walton
CDCloudflare Developers
Created by Philip Walton on 6/19/2024 in #pages-help
Differences between fetch() and env.ASSETS.fetch()
...or is the assumption that everything is a "cache hit" (even if it's located in another edge node) and the better thing to measure is the time it takes to fetch the response?
19 replies
CDCloudflare Developers
Created by Philip Walton on 6/19/2024 in #pages-help
Differences between fetch() and env.ASSETS.fetch()
Regarding my question about Cf-Cache-Status is threre any way to determine whether there was a cache hit when requesting an asset via env.ASSETS.fetch()? Ideally without manually implenting caching via the Cache API?
19 replies
CDCloudflare Developers
Created by Philip Walton on 6/19/2024 in #pages-help
Differences between fetch() and env.ASSETS.fetch()
I didn't notice a difference before because my external origin had the same content as my pages account.
19 replies
CDCloudflare Developers
Created by Philip Walton on 6/19/2024 in #pages-help
Differences between fetch() and env.ASSETS.fetch()
This code doesn't error, but it looks like it actually is fetching the / path from the assets. (I.e. the "origin part of the URL is ignored and only the "pathname" part is used.)
19 replies
CDCloudflare Developers
Created by Philip Walton on 6/19/2024 in #pages-help
Differences between fetch() and env.ASSETS.fetch()
Ok, I just checked with the following code:
export async function onRequestGet(context) {
return context.env.ASSETS.fetch('https://example.com');
}
export async function onRequestGet(context) {
return context.env.ASSETS.fetch('https://example.com');
}
19 replies
CDCloudflare Developers
Created by Philip Walton on 6/19/2024 in #pages-help
Differences between fetch() and env.ASSETS.fetch()
ASSETS.fetch is a Pages API for fetching assets. It does not fetch an origin or anything, it's just for fetching static assets
This is not quite true, as both of the screenshots I mentioned above were from assets fetched from an external origin. So both fetch() and env.ASSETS.fetch() support that, they just have different behavior. It sounds like the answer to my question is that "no" there is no documentation that explains the difference. I'd like to suggest that there should be.
19 replies
CDCloudflare Developers
Created by Philip Walton on 6/19/2024 in #pages-help
Differences between fetch() and env.ASSETS.fetch()
Notice how the first screenshot includes the Cf-Cache-Status header (but no ETag header). And the second screenshot includes the ETag header, but no Cf-Cache-Status header. The first example also retains the X-Cache X-Cache-Hits X-Served-By and X-Timer headers from the origin server, whereas the second example strips those headers.
19 replies
CDCloudflare Developers
Created by Philip Walton on 6/19/2024 in #pages-help
Differences between fetch() and env.ASSETS.fetch()
No description
19 replies
CDCloudflare Developers
Created by Philip Walton on 6/19/2024 in #pages-help
Differences between fetch() and env.ASSETS.fetch()
No description
19 replies
CDCloudflare Developers
Created by Philip Walton on 6/19/2024 in #pages-help
Differences between fetch() and env.ASSETS.fetch()
Thanks for the links @cocosrobal but those resources don't cover the differences between the two fetch() methods, nor do they explain why env.ASSETS.fetch() would have different behavior when it comes to ETag and Cf-Cache-Status headers.
19 replies
CDCloudflare Developers
Created by Philip Walton on 6/19/2024 in #pages-help
Differences between fetch() and env.ASSETS.fetch()
I also just noticed that responses served from Pages functions do not contain the Cf-Cache-Status header, whereas responses served from my old Worker file did. That header was useful to determine my cache hit ratio. Is there a configuration option I can set to add that header back?
19 replies