I'm using the following function in a Firefox extension to check if a file exists in another extension:
function chromeFileExists(fileLoc) // in extension package
{
var xmlhttp = new window.XMLHttpRequest();
try {
xmlhttp.open("GET", "chrome://"+fileLoc, false);
xmlhttp.send(null);
var xmlDoc = xmlhttp.responseXML.documentElement;
}
catch(ex) {
return false;
}
return true;
}
But the problem is, of course, that if the file does exist, it actually loads the file before it tells me. Some of the files I'm querying are over 1MB in size, so I'd rather not load them into memory.
How to check for the existence and return without loading the file itself? I've tried working with onreadystatechange, but can't seem to figure it out.