I want to detect in a script, which could be deployed beyond my control, whether the page was delivered with a HTTP status of 200, 404 or 500 etc.
This can't be done, right?
Just use Chrome browser. Hit F12 to get developer tools and look at the network tab. Shows you all status codes, whether page was from cache etc.
To get the status code of an HTTP request made with the fetch method, access the status property on the response object. The response. status property contains the HTTP status code of the response, e.g. 200 for a successful response or 500 for a server error. Copied!
These are the HTTP status codes that have the greatest impact on UX and SEO: 200 – Ok – the page is successfully loaded – normal. 201 – Created (see more details below) 301 – Permanent redirect.
An HTTP status code is a message a website's server sends to the browser to indicate whether or not that request can be fulfilled. Status codes specs are set by the W3C. Status codes are embedded in the HTTP header of a page to tell the browser the result of its request.
Have the page make a XMLHttpRequest to itself (using location.href
or document.URL
) and check the HTTP status you get. Seems to be pretty portable way to me. Why you would do a thing like this is beyond my understanding though ;)
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