How to check if origin server is available and able to complete Ajax requests using JavaScript
I’m wondering what would be the simplest method, using JavaScript, to check if the origin server is accessible and available to process Ajax requests? To provide more context: there are pages on this site, built in WordPress, that provide filterable lists of posts, and each interaction with a filter sends an Ajax request. The site is configured with an edge cache such that if the origin goes down, visitors would still access a cached version of the page. If, however, a visitor is viewing a cached page under these circumstances, the filters will not work, as Ajax requests to the origin will fail. Essentially, I would like a way to detect if a visitor is, in fact, viewing a static version of the page served by the edge cache and, if so, append a class to the <body>
of the document.