Why `fetch` add `max-age=14400` automatically?

const request = new Request(originURL)
fetch(request)

The response from origin:

cache-control: max-age=0, s-maxage=7200, stale-while-revalidate=86400

but fetch's response gives:

cache-control: max-age=14400, s-maxage=7200, stale-while-revalidate=86400

Why it modified the max-age automatically? How can I keep it as the original one?

That sure looks like Cloudflare’s standard 4-Hour cache in the dashboard setting. You can also try “Respect Existing Headers”.

2 Likes

Thanks! You’re right.

I tried to change the “Browser Cache TTL” to 30min via page rules, and that changes the “max-age” to “1800”.

but I couldn’t find the “Respect Existing Headers” option in page rules.
I could find the “Respect Existing Headers” option under the “Caching → Browser Cache TTL”, but that will effect all my subdomains.
Do you have any idea for this?

It looks like only Enterprise plan users have the Browser Cache TTL - “Respect Existing Headers” option in page rules.

2 Likes

You can probably “reverse Page Rule” that. Set Global cache to respect existing headers, then create a Page Rule for that worker’s route that’s fairly benign (always use https, etc.) just to preempt a match, then Page Rule #2 for example.com/* to set browser cache to 4 hours.

1 Like

on CF Enterprise it’s still there at least

The global “Browser Cache TTL” setting has the option to respect existing headers in all plans, but not in page rules.

I see what you meant, I thought you meant you can set it in page rules only :sweat_smile:

1 Like

Thanks guys! I got the idea.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.