Checking if a resource exists on a server requires sending a HTTP
request and receiving the response. TCP communication can take some
amount of time, e.g. if the server is busy, some router between the
client and the server does not work
correctly, the network is down etc.

That's why asynchronous requests are always preferred. Even if you think
that the request should take only milliseconds, it might sometimes be
seconds due to some network problems. And – as we all know – blocking
the main thread for some seconds is a big no-no.

All that being said, here is a possible implementation for a
fileExists() method. You should not use it on the main thread,
you have been warned!

The HTTP request method is set to "HEAD", so that the server sends
only the response header, but no data.