V
V
vadim_tur2015-10-26 16:13:35
JavaScript
vadim_tur, 2015-10-26 16:13:35

Checking if a js file exists?

I check the existence of the file in the following way:

$.ajax("http://yoursite.ru/your/cool/path/your_cool_file.mp3", {
    success: function() {
        // Run your mp3 player
    },
    error: function() {
        alert("An error occured. We can not play the audio");
    }
});

But the question arose, would this slow down the script or increase the load on the server? that is, does the client receive redundant information with this request? 'Cause I just want the headers.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivanq, 2015-10-26
@vadim_tur

$.ajax("http://yoursite.ru/your/cool/path/your_cool_file.mp3", {
    success: function() {
        // Run your mp3 player
    },
    error: function() {
        alert("An error occured. We can not play the audio");
    },
    method: "HEAD"
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question