I'm making an ajax request to a site behind Cloudflare. After 100 seconds, I get a 524. However I'm unable to process that 524 in my Javascript as the error page is served directly by Cloudflare and does not contain the required Access-Control-Allow-Origin headers.
I wish to retry the query in the event of getting a 524.
The 524 A Timeout Occurred error is a Cloudflare-specific HTTP status code that indicates that the connection to the server has been closed due to a timeout. Depending on the context, the error might prevent you from loading a web page, signing in to an online gaming platform, or using a piece of software.
Disable the Opcode Cache and “Purge All Caches” in W3TC. This worked for us in fixing the 524 error which used to happen frequently when making edits and saving pages in WordPress.
If you know that CloudFlare edge will wait for a HTTP response from the server for exactly 100 seconds, then you could just setup a timeout equal to 100 seconds on the ajax request. And retry the query after the timeout.
Alternatively, you can move this request into subdomain which is not under cloud flare proxy.
Another idea is to use a reverse proxy and adding CORS headers. In the Apache that would be
<LocationMatch "/ajax-request-used-in-js">
ProxyPass http://example.com/ajax
Header add "Access-Control-Allow-Origin" "*"
</LocationMatch>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With