OpChan/app/src/utils/urlLoads.ts

24 lines
513 B
TypeScript
Raw Normal View History

/**
* Utility to check if a URL loads successfully within a timeout
*/
2025-08-30 18:34:50 +05:30
export async function urlLoads(
url: string,
timeoutMs: number = 5000
): Promise<boolean> {
try {
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
2025-08-30 18:34:50 +05:30
const response = await fetch(url, {
method: 'HEAD',
signal: controller.signal,
2025-08-30 18:34:50 +05:30
cache: 'no-cache',
});
2025-08-30 18:34:50 +05:30
clearTimeout(timeoutId);
return response.ok;
2025-08-28 19:07:26 +05:30
} catch {
return false;
}
2025-08-30 18:34:50 +05:30
}