Home > Enterprise >  Fetch but only get status?
Fetch but only get status?

Time:05-19

When a new domain is attached, I made a logic to check whether the domain works normally through fetch.

fetch("https://"   domain).then((result)=>{
const isOk = result.status === 200
...
 })

However, I thought it would be inefficient to fetch the entire HTML doc through fetch just to check if it works. How can I get only the status value?

CodePudding user response:

You can request only the headers, as opposed to the whole page, using the HEAD method. The server should return the same headers as it would if the GET method was used, but no body. You can request this behaviour using the method option:

fetch(url, { method: 'HEAD' })
  • Related