Checking If A File Exists

One thing that all of the solutions posted so far run into is CORS issues when trying to check for content on other domains/hosts than your own. Here is one approach using a CORS bypass proxy that solves that problem:

let CORS_override = "https://cors-anywhere.herokuapp.com/";

function doesFileExist(pathToFile) {
  //
  // Remove CORS_override from the 'fetch' call if you'll 
  // only be checking for files on your own domain
  //
  fetch(CORS_override + pathToFile)
    .then(function (response) {
      if (response.status != "404") {
        console.log(pathToFile + " exists: " + response.statusText);
      } else {
        console.log(pathToFile + " does not exist: " + response.statusText);
      }
    })
    .catch(function (error) {
      console.log("Probably a network error!");
    });
}

doesFileExist("https://www.kirupa.com/ssi/newDesign/kirupaLogo_large2.png");
doesFileExist("https://www.kirupa.com/ssi/newDesign/kirupaLogo_large.png");