Caching Multiple Versions of SSR Page Based on cf-ipcountry Header

Hello Cloudflare Community,

I am currently working on a Next.js application where I use server-side rendering (SSR) to generate a page. Depending on the value of the cf-ipcountry header, I serve two different versions of this page.

My goal is to cache both versions of the page and serve the appropriate version to users based on their country. Could someone guide me on how to achieve this with Cloudflare?

Here’s a bit more detail about my setup:

  1. When a request comes in, I check the cf-ipcountry header.
  2. Based on the country code, I generate and serve either Version A or Version B of the page.

I am looking for the best approach to:

  • Cache both versions of the page separately.
  • Ensure that users receive the correct version based on their cf-ipcountry header.

Any insights or suggestions on how to configure Cloudflare for this use case would be greatly appreciated.

Thank you!