How can i check given url is got valid image or 404 if not valid (404) then recheck after 20 seconds and try like this for 5 mins with Javasript
checkFileExists = function(){
    $.ajax({
        type: 'HEAD',
        url: fileUrl,
        crossDomain: true,
        success: function(response) {
          // Further processing if file exists
          fileExists = true;
          console.log(response);
        },
        error: function(error) {
            // File does not exists, run through function again-
          console.log(error);
          fileExists = false;
        }
    });
  }
if(!fileExists) {
   setTimeout(function(){
      checkFileExists();
   }, 20000);
}
But its not working it throws error 'XMLHttpRequest cannot load XXXX No 'Access-Control-Allow-Origin' header is present on the requested resource.'
** and my file url is 'https://drive.google.com/thumbnail?xxxx' im requesting from my localhost
 
     
     
     
    