0

Hi I am using Angular and iframe. I would like to detect if the target website is online or not before load it into the iframe. I am currently using the following code

try {
  await this._httpClient.get(url, { observe: 'response' }).toPromise();
} catch (error) {
  return error.status === 200;
}

However, it takes more than 20 seconds to check one website when the website it offline, but quite quick when the website is online. Is there faster way to detect if a target website is online or not? Thank you

2

1 Answer 1

1

You can send request for other static small file like simple css file or image file of that site instead of site content.

Sign up to request clarification or add additional context in comments.

2 Comments

Hi Romeo, thank you for your suggestion. However, the issue of my code is that when the website is offline, it takes more than 20 seconds to return a timeout, then it will move to check the next website. So not exactly sure how much loading a small static file will help. Actually when the website is online, my code detects much quicker than detecting an offline website.
If you think so, you can give timeout before sending request.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.