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.
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…