How to detect blank page and always revalidate it on request?

Hi,

I am using GTranslate to translate our website from English to other languages. Meanwhile, I also use Cloudflare to cache the translated page generated by GTranslate.

Sometimes, Cloudflare will cache a blank page, like this: https://www.datanumen.com/de/Archivreparatur/. By pressing Ctrl + F5, I can get the corrected contents. However, how to detect blank page and always force revalidate so that the visitors can see the correct contents, as they will not press Ctrl + F5.

I can detect 404 status code and use the following one to force revalidate, as below:

Header set CDN-Cache-Control “no-cache, must-revalidate, max-age=0” “expr=%{REQUEST_STATUS} == 404”
Header set Cloudflare-CDN-Cache-Control “no-cache, must-revalidate, max-age=0” “expr=%{REQUEST_STATUS} == 404”

But for the above blank page, its status is 200 so I cannot know how to detect it.

Hi,

That would be very hard, if not impossible, without Workers.

If Workers is not an option, you should perhaps consider:

  1. reducing the Edge Cache TTL (via Cloudflare-CDN-Cache-Control or some other setting under Dashboard > Caching), or
  2. creating a cronjob that would curl your pages and check the result, then purge the respective URL from Cloudflare cache via API.

Thank you for your reply.

I have compared the blank page and those with a contents, and find they have different response fields.

Blank page:

Valid page:

The blank page missing fields, like x-gt-server, x-gt-cache-origurl, etc.

So is it possible to create a rule that will NOT cache if these fields in response header are missing?

I don’t think so. Response headers come too late in the game. Cloudflare must make the decision to serve from cache before it reaches your origin, otherwise it wouldn’t make sense to cache.

But you can check your plugin’s documentation to see if it has an option to set a cookie. If so, or if you manage to set a cookie for translated pages with your origin .htaccess, then you could create a Cache Rule using that cookie as part of the condition to cache.

It seems the x-gt fields are also cached. So if Cloudflare can check if the cached response contains these fields, then it can serve the client, otherwise, it will go to the origin.

If you’re on an Enterprise Plan, you can use headers as part of your cache keys. Just create a Cache Rule and head down to the Cache Key section. In combination with URL parameters, you could then have 2 separate cache keys, one for when the cookie is present (cache), and another for when it isn’t (bypass).

If you’re not on an Enterprise Plan, you could try something similar with Workers. I’m not saying it’s possible, though. You may need to research and bring your questions to the Cloudflare Developers channel on Discord…

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