I have a 2 hosts. The first one is for media files (mp3, mp4 and images) and the 2nd is where the site is. They are under 2 different domains (for example: https://example.com and https://files.example.com). There is a page where I have to check if a specific video (mp4 file) exists. I did it like that:
function CheckFileExists(url) {
jQuery.ajax({
url: url,
dataType: "jsonp"
}).done(function (data) {
return true;
}).fail(function (data) {
return false;
})
}
the dataType jsonp is set because it was the only way I've found to fix the "Access to XMLHttpRequest at 'https://files.example.com/videos/my_vid.mp4' from origin 'https://example.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource." problem. Without that parameter - the function always returns false.
Anyway, now there is another problem. the ajax call takes ages! it seems that it tries to load the entire video - which of course is not what I need.
Do you have any idea how to solve it?
- It must be a javaScript check and not in server side.
- The file domain is different then the site
- I only want to check if the file exist and not load the file
Thanks a lot!