How to exclude specific user agent from CloudFlare's caching?

I’m looking for solution how force Cloudflare to serve non-cached version of the website only for specific user agent.

AFAIK this is not possible out-of-the-box. Maybe with workers.

Well, I did not try this but either you give Workers a try, or think as weird like I do.

create a sub domain

Do a User Agent based redirect on your server to

Write a pagerule like:
Cache Level: bypass

Use the fancy new firewall feature to restrict access to this sub domain to the UA in question.
Something like

(http.user_agent ne “Your User Agent Here” and eq “”) - > Block

Again, I know this sounds weird and I don’t know if it would work.

We may be able to help you better if we knew your use case scenario. Can you explain more about what you’re trying to accomplish?

I’m working on react website and trying to serve different(already pre-rendered HTML) content for some search engines only. My server already handle this and depends of user agent serves full website with react or pre-rendered html. The problem starts when I add caching layer to Cloudflare. Cloudflare will always serve cached version and all boots will always get cached version with react.

That’s not a recommended practice. Search engines (google at least) can detect when you’re doing that and it makes them unhappy. It’s a black-hat seo tactic that defeats their purpose. I’m not saying you’re doing anything malevolent, but that’s what a search spider will think.

With a combination of robots.txt (make search engines not look at live/dynamic pages) and sitemap.xml (feed search engines static pages hidden from the public) you can probably get your desired result without getting negative seo.

But I’m not sure of the overall goal. We still don’t know the reason for the two different views of the same website.

1 Like

Some SEO bots (for example Bing) have a problem with websites using React. I’m able to pre-render react components on the server and serve whole page as static html. Content is exactly the same, the way how is generated is different.

Oh, I see. That’s a tough one. I’ll try to give it some thought, but no promises.

This topic was automatically closed after 14 days. New replies are no longer allowed.