ChatGPT suggested me to use this method
async function checkFileExists(path) {
try {
const response = await fetch(path, { method: 'HEAD' });
return response.ok;
} catch (error) {
console.error('Error checking file existence:', error);
return false;
}
}
Theoretically, the ChatGPT solution is clean and logical and should have worked. However, it overlooked the fact that using method: ‘HEAD’ could trigger CORS errors.
If you can think of a better, more robust solution, please let me know. Also, if you have a better way to prompt ChatGPT, I would love to know as well!